# injectGrid

> _Since v0.6.0_

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.

## Usage

```typescript
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);
  }
}
```

```ts
injectGrid(selector: string): InjectGridReturn<TRow>
```

## Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| `selector` | <code>string</code> | Optional 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'`. |

## Returns

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