Skip to content

injectGrid

Angular inject function for programmatic access to a grid instance.

This function should be called in the constructor or as a field initializer of an Angular component that contains a <tbw-grid> element.

import { Component } from '@angular/core';
import { Grid, injectGrid } from '@toolbox-web/grid-angular';
@Component({
selector: 'app-my-grid',
imports: [Grid],
template: `
<button (click)="handleResize()">Force Layout</button>
<button (click)="handleExport()" [disabled]="!grid.isReady()">Export</button>
<tbw-grid [rows]="rows" [gridConfig]="config"></tbw-grid>
`
})
export class MyGridComponent {
grid = injectGrid<Employee>();
async handleResize() {
await this.grid.forceLayout();
}
async handleExport() {
const config = await this.grid.getConfig();
console.log('Exporting with columns:', config?.columns);
}
}
injectGrid(selector: string): InjectGridReturn<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'.

InjectGridReturn<TRow> - Object with grid access methods and state signals

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