# SelectionMethods

Selection methods returned from injectGridSelection.

Uses lazy discovery - the grid is found on first method call, not during initialization.
This ensures it works with lazy-rendered tabs, conditional rendering, etc.

## Properties

| Property | Type | Description |
| -------- | ---- | ----------- |
| `selectAll` | <code>() =&gt; void</code> | Select all rows (row mode) or all cells (range mode). |
| `clearSelection` | <code>() =&gt; void</code> | Clear all selection. |
| `getSelection` | <code>() =&gt; <a href="/grid/plugins/selection/interfaces/selectionresult/">SelectionResult</a> &#124; unknown</code> | Get the current selection state (imperative, point-in-time snapshot). For reactive selection state, use the `selection` signal instead. |
| `isCellSelected` | <code>(row: number, col: number) =&gt; boolean</code> | Check if a specific cell is selected. |
| `setRanges` | <code>(ranges: <a href="/grid/plugins/selection/interfaces/cellrange/">CellRange</a>[]) =&gt; void</code> | Set selection ranges programmatically. |
| `selection` | <code>Signal&lt;<a href="/grid/plugins/selection/interfaces/selectionresult/">SelectionResult</a> &#124; unknown&gt;</code> | Reactive selection state. Updates automatically whenever the selection changes. Null when no SelectionPlugin is active or no selection has been made yet. |
| `selectedRowIndices` | <code>Signal&lt;number[]&gt;</code> | Reactive selected row indices (sorted ascending). Updates automatically. Convenience signal for row-mode selection — returns `[]` in cell/range modes or when nothing is selected. |
| `selectedRows` | <code>Signal&lt;TRow[]&gt;</code> | Reactive selected row objects. Updates automatically whenever the selection changes. Works in all selection modes (row, cell, range) — returns the actual row objects from the grid's processed (sorted/filtered) rows. |
| `isReady` | <code>Signal&lt;boolean&gt;</code> | Signal indicating if grid is ready. The grid is discovered lazily, so this updates when first method call succeeds. |

### Property Details

#### selection

```typescript
readonly selection = injectGridSelection();

// In template:
// {{ selection.selection()?.ranges?.length ?? 0 }} cells selected

// In computed:
readonly hasSelection = computed(() => (this.selection.selection()?.ranges?.length ?? 0) > 0);
```

---

#### selectedRowIndices

Reactive selected row indices (sorted ascending). Updates automatically.
Convenience signal for row-mode selection — returns `[]` in cell/range modes
or when nothing is selected.

**Prefer `selectedRows`** for getting actual row objects — it handles
index-to-object resolution correctly regardless of sorting/filtering.

```typescript
readonly selection = injectGridSelection();

// In template:
// {{ selection.selectedRowIndices().length }} rows selected
```

---

#### selectedRows

Reactive selected row objects. Updates automatically whenever the selection changes.
Works in all selection modes (row, cell, range) — returns the actual row objects
from the grid's processed (sorted/filtered) rows.

This is the recommended way to get selected rows. Unlike manual index mapping,
it correctly resolves rows even when the grid is sorted or filtered.

```typescript
readonly selection = injectGridSelection<Employee>();

// In template:
// {{ selection.selectedRows().length }} rows selected

// In computed:
readonly hasSelection = computed(() => this.selection.selectedRows().length > 0);
```

---
