# Angular

> Use Birch UI Grid in Angular with the standalone BirchGridComponent, signal inputs, typed outputs, the grid API and server-side rendering.

`@birchui/angular` provides standalone components with `OnPush` change detection, signal inputs and `output()` events. `BirchGridComponent` (selector `birchui-grid`) wraps the MIT grid from `@birchui/core`. It supports Angular 17.3 and later, with zone.js or zoneless change detection, and is safe for server-side rendering.

## Install

```bash
npm install @birchui/angular @birchui/core
```

## A complete example

```ts title="orders.component.ts"
import { ChangeDetectionStrategy, Component, signal, viewChild } from '@angular/core';
import { BirchGridComponent } from '@birchui/angular';
import type { CellEvent, CellValueChangedEvent, ColumnDef, GridOptions } from '@birchui/core';

interface Order {
  id: string;
  customer: string;
  placedAt: string;
  status: 'open' | 'shipped' | 'cancelled';
  total: number;
}

const usd = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' });

@Component({
  selector: 'app-orders',
  standalone: true,
  imports: [BirchGridComponent],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <div class="toolbar">
      <input type="search" placeholder="Search orders" (input)="search.set($any($event.target).value)" />
      <button type="button" (click)="exportCsv()">Export CSV</button>
      <span>{{ selected().length }} selected</span>
    </div>

    <birchui-grid
      class="orders"
      [columns]="columns"
      [rows]="orders()"
      [quickFilter]="search()"
      [options]="options"
      (cellClick)="openOrder($event)"
      (cellValueChanged)="saveChange($event)"
      (selectionChanged)="selected.set($event.selected)"
    />
  `,
  styles: `
    .orders {
      height: 480px;
    }
  `,
})
export class OrdersComponent {
  private readonly grid = viewChild.required<BirchGridComponent<Order>>(BirchGridComponent);

  readonly search = signal('');
  readonly selected = signal<Order[]>([]);
  readonly orders = signal<Order[]>([
    { id: 'SO-10421', customer: 'Northwind Traders', placedAt: '2026-11-02', status: 'open', total: 1840.5 },
    { id: 'SO-10422', customer: 'Contoso Ltd', placedAt: '2026-11-03', status: 'shipped', total: 312 },
    { id: 'SO-10423', customer: 'Fabrikam Inc', placedAt: '2026-11-03', status: 'cancelled', total: 96.4 },
  ]);

  readonly columns: ColumnDef<Order>[] = [
    { field: 'id', header: 'Order', width: 120, pinned: 'left' },
    { field: 'customer', header: 'Customer', flex: 1, filter: 'text', editable: true },
    { field: 'placedAt', header: 'Placed', type: 'date', filter: 'date' },
    { field: 'status', header: 'Status', filter: 'set', editable: true, editor: 'select', options: ['open', 'shipped', 'cancelled'] },
    { field: 'total', header: 'Total', type: 'number', format: (value) => usd.format(Number(value)) },
  ];

  readonly options: Partial<GridOptions<Order>> = {
    getRowId: (order) => order.id,
    rowSelection: 'multiple',
    checkboxSelection: true,
    pagination: { pageSize: 50 },
    sort: [{ colId: 'placedAt', dir: 'desc' }],
  };

  openOrder(event: CellEvent<Order>): void {
    if (event.row && event.colId === 'id') console.info('Open order', event.row.id);
  }

  saveChange({ row, colId, newValue }: CellValueChangedEvent<Order>): void {
    console.info(`Order ${row.id}: ${colId} is now ${String(newValue)}`);
  }

  exportCsv(): void {
    this.grid().api?.downloadCsv({ fileName: 'orders.csv' });
  }
}
```

The host element is `display: block`. Give it a height in your styles; the grid fills it.

## Inputs

| Input | Type | Notes |
| --- | --- | --- |
| `options` | `Partial<GridOptions<TRow>>` | Any [grid option](https://docs.birchui.com/api/core.md#gridoptions) |
| `columns` | `ColumnDef<TRow>[]` | Shortcut for `options.columns` |
| `rows` | `TRow[]` | Shortcut for `options.rows` |
| `theme` | `'light' \| 'dark' \| 'auto'` or a theme class suffix | Shortcut for `options.theme` |
| `quickFilter` | `string` | Shortcut for `options.quickFilter` |
| `licenseKey` | `string` | Shortcut for `options.licenseKey` |

The inputs are merged into one options object, and a shortcut input with a defined value overrides the same key in `options`. After each change, only the keys whose value changed by identity are sent to `update()`. The grid is never recreated.

To change rows, columns or nested options, pass a new array or object. Mutating one in place is not detected:

```ts
addOrder(order: Order): void {
  this.orders.update((orders) => [...orders, order]);
}
```

For high-frequency updates, use the API instead: `this.grid().api?.applyTransaction({ update: [order] })`.

## Outputs

There is one output for every grid event, with the same name and a typed payload: `ready`, `cellClick`, `cellDoubleClick`, `cellKeyDown`, `cellValueChanged`, `rowClick`, `selectionChanged`, `sortChanged`, `filterChanged`, `columnResized`, `columnMoved`, `columnPinned`, `columnVisible`, `columnStateChanged`, `modelUpdated`, `focusChanged`, `viewportScroll`, `pageChanged`, `rowExpanded`, `editStart` and `editStop`.

```html
<birchui-grid
  [columns]="columns"
  [rows]="orders()"
  (sortChanged)="saveSort($event.sort)"
  (columnStateChanged)="saveLayout($event.state)"
  (pageChanged)="page.set($event.page)"
/>
```

Payload types are listed in the [events reference](https://docs.birchui.com/grid/events.md).

## Typed generics

`BirchGridComponent` is generic over the row type. Templates infer `TRow` from `[rows]` and `[columns]`, so `$event.row` in every output is typed. For `viewChild`, pass the type argument explicitly: `viewChild.required<BirchGridComponent<Order>>(BirchGridComponent)`.

## The grid API

The component's `api` property returns the [`GridApi<TRow>`](https://docs.birchui.com/api/core.md#gridapi) once the grid exists. It is `undefined` before the first browser render and after the component is destroyed. Read it in event handlers, after `(ready)`, or from `afterNextRender`:

```ts
import { afterNextRender, Component, input, viewChild } from '@angular/core';
import { BirchGridComponent } from '@birchui/angular';
import type { ColumnDef } from '@birchui/core';

interface Technician {
  id: string;
  name: string;
  depot: string;
  openJobs: number;
}

@Component({
  selector: 'app-technicians',
  standalone: true,
  imports: [BirchGridComponent],
  template: `<birchui-grid class="technicians" [columns]="columns" [rows]="technicians()" />`,
})
export class TechniciansComponent {
  private readonly grid = viewChild.required<BirchGridComponent<Technician>>(BirchGridComponent);

  readonly technicians = input.required<Technician[]>();
  readonly columns: ColumnDef<Technician>[] = [
    { field: 'name', header: 'Technician', flex: 1 },
    { field: 'depot', header: 'Depot', filter: 'set' },
    { field: 'openJobs', header: 'Open jobs', type: 'number' },
  ];

  constructor() {
    afterNextRender(() => {
      const saved = localStorage.getItem('technician-columns');
      if (saved) this.grid().api?.applyColumnState(JSON.parse(saved));
    });
  }
}
```

The `ready` output carries the API as well: `(ready)="$event.api.autosizeColumns()"`.

## Grid Pro

Pass modules and Pro options through `options`, and set the license key once at startup:

```ts title="main.ts"
import { bootstrapApplication } from '@angular/platform-browser';
import { setLicenseKey } from '@birchui/license';
import { AppComponent } from './app/app.component';
import { appConfig } from './app/app.config';
import { environment } from './environments/environment';

setLicenseKey(environment.birchLicenseKey);

bootstrapApplication(AppComponent, appConfig).catch((error) => console.error(error));
```

```ts title="revenue.component.ts"
import { Component, input } from '@angular/core';
import { BirchGridComponent } from '@birchui/angular';
import { AllProModules } from '@birchui/grid-pro';
import type { ColumnDef, GridOptions } from '@birchui/core';

interface Sale {
  region: string;
  country: string;
  revenue: number;
}

@Component({
  selector: 'app-revenue',
  standalone: true,
  imports: [BirchGridComponent],
  template: `<birchui-grid class="revenue" [columns]="columns" [rows]="sales()" [options]="options" />`,
  styles: `.revenue { height: 520px; }`,
})
export class RevenueComponent {
  readonly sales = input.required<Sale[]>();

  readonly columns: ColumnDef<Sale>[] = [
    { field: 'region', header: 'Region', rowGroup: true },
    { field: 'country', header: 'Country' },
    { field: 'revenue', header: 'Revenue', type: 'number', aggFunc: 'sum' },
  ];

  readonly options: Partial<GridOptions<Sale>> = {
    modules: AllProModules,
    groupDefaultExpanded: 1,
    groupPanel: true,
    statusBar: { rowCount: true, aggregates: ['sum', 'avg'] },
  };
}
```

You can also pass a key per grid with the `[licenseKey]` input.

## SSR and hydration

Importing the package has no side effects and never touches `window` or `document`. On the server, `<birchui-grid>` renders as an empty host element. The grid is created in `afterNextRender`, which runs only in the browser after hydration, so no extra configuration is needed for `@angular/ssr`.

Give the host a height in your CSS so the server-rendered page reserves the space and nothing shifts when the grid mounts.

## Change detection

The grid and its DOM listeners run outside the Angular zone, so scrolling and pointer movement do not trigger change detection. An output re-enters the zone only when it emits and something is listening to it. Zoneless apps that use `provideZonelessChangeDetection()` need no extra setup; signal updates in your output handlers schedule rendering as usual.

## Wrapping your own widgets

`injectBirchWidget(definition, outputs, options)` is the helper the grid component is built on. Call it in the injection context of your own standalone component to wrap any widget that follows the Birch UI widget contract. It creates the widget after the first browser render, sends changed options to `update()`, forwards events to your outputs and destroys the widget with the component. `withOverrides(base, overrides)` merges an `options` input with shortcut inputs the same way the grid component does.

## Event Calendar

`@birchui/angular` has no calendar component. Wrap `calendarDefinition` from `@birchui/calendar` in a standalone component of your own with `injectBirchWidget`, as described in [Wrapping your own widgets](#wrapping-your-own-widgets). Declare one output per calendar event, or call `createCalendar` yourself inside `afterNextRender`. See the [Event Calendar overview](https://docs.birchui.com/calendar/overview.md) for its options and events.

### Other Birch UI products

Gantt, Pivot Studio, Charts, the diagram editor, the spreadsheet, the form renderer and the Form Builder work the same way: pass `ganttDefinition` from `@birchui/gantt`, `pivotStudioDefinition` from `@birchui/pivot-studio`, `chartDefinition` from `@birchui/charts`, `diagramDefinition` from `@birchui/diagram`, `spreadsheetDefinition` from `@birchui/spreadsheet`, `formDefinition` from `@birchui/forms` or `formBuilderDefinition` from `@birchui/forms/builder` to `injectBirchWidget`. The [Gantt](https://docs.birchui.com/gantt/overview.md), [Pivot Studio](https://docs.birchui.com/pivot-studio/overview.md), [Charts](https://docs.birchui.com/charts/overview.md), [Diagram](https://docs.birchui.com/diagram/overview.md), [Spreadsheet](https://docs.birchui.com/spreadsheet/overview.md) and [Forms](https://docs.birchui.com/forms/overview.md) overviews have complete examples.

## Scheduler

`BirchSchedulerComponent` comes from the secondary entry point `@birchui/angular/scheduler`, so apps that only use the grid never load scheduler code. See [Using the Scheduler in your framework](https://docs.birchui.com/frameworks/scheduler.md).

## Next steps

- [Columns](https://docs.birchui.com/grid/columns.md), [filtering](https://docs.birchui.com/grid/filtering.md) and [editing](https://docs.birchui.com/grid/editing.md).
- The [@birchui/angular API reference](https://docs.birchui.com/api/angular.md).
