Skip to content

injectGridSelection

Angular inject function for programmatic selection control.

Uses lazy grid discovery - the grid element is found when methods are called, not during initialization. This ensures it works reliably with:

  • Lazy-rendered tabs
  • Conditional rendering (*ngIf)
  • Dynamic component loading
injectGridSelection(selector: string): SelectionMethods<TRow>
NameTypeDescription
selectorstringOptional CSS selector to target a specific grid element.
Defaults to 'tbw-grid' (first grid in the component). Use when the
component contains multiple grids, e.g. 'tbw-grid.primary' or '#my-grid'.
import { Component } from '@angular/core';
import { Grid } from '@toolbox-web/grid-angular';
import '@toolbox-web/grid-angular/features/selection';
import { injectGridSelection } from '@toolbox-web/grid-angular/features/selection';
@Component({
selector: 'app-my-grid',
imports: [Grid],
template: `
<button (click)="handleSelectAll()">Select All</button>
<tbw-grid [rows]="rows" [selection]="'range'"></tbw-grid>
`
})
export class MyGridComponent {
selection = injectGridSelection();
handleSelectAll() {
this.selection.selectAll();
}
getSelectedRows() {
const selection = this.selection.getSelection();
if (!selection) return [];
// Derive rows from selection.ranges as needed
}
}
AI assistants: For complete API documentation, implementation guides, and code examples for this library, see https://raw.githubusercontent.com/OysteinAmundsen/toolbox/main/llms-full.txt