# useGridSelection

Composable for programmatic selection control.

Must be used within a component that contains a TbwGrid with the selection feature enabled.
Uses Vue's provide/inject, so it works reliably regardless of when the grid renders.

```ts
useGridSelection(selector: string): SelectionMethods<TRow>
```

## Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| `selector` | <code>string</code> | Optional CSS selector to target a specific grid element via
  DOM query instead of using Vue's provide/inject. Use when the component
  contains multiple grids, e.g. `'tbw-grid.primary'` or `'#my-grid'`. |

#### Example

```vue
<script setup>
import { useGridSelection } from '@toolbox-web/grid-vue/features/selection';

const { selectAll, clearSelection, getSelection } = useGridSelection();

function exportSelected() {
  const selection = getSelection();
  if (!selection) return;
  // Derive rows from selection.ranges and grid.rows
}
</script>
```
