Skip to content

Angular

next-grid-angular wraps next-grid-js/core as a standalone <next-grid> component supporting both zoneless Angular applications and zone.js.

Terminal window
npm install next-grid-angular next-grid-js

Peers: next-grid-js 0.1, @angular/core 21 or 22 (no @angular/common or zone.js required).

Add 'next-grid-js/styles.css' to your global styles array in angular.json.

import { Component, signal } from '@angular/core';
import type { ColumnDef, Grid, SortChangedEvent } from 'next-grid-js/core';
import { NextGrid } from 'next-grid-angular';
interface Order {
id: string;
customer: string;
total: number;
}
@Component({
selector: 'app-orders',
imports: [NextGrid],
template: `
<next-grid
style="height: 400px"
[columnDefs]="columnDefs"
[rowData]="orders()"
[getRowId]="rowId"
(sortChanged)="onSort($event)"
(gridReady)="grid = $event"
/>
`,
})
export class OrdersComponent {
readonly columnDefs: ColumnDef<Order>[] = [
{ colId: 'customer', key: 'customer', isSortable: true },
{ colId: 'total', key: 'total', cellDataType: 'number' },
];
readonly orders = signal<Order[]>([]);
readonly rowId = (order: Order): string => order.id;
grid: Grid<Order> | null = null;
onSort(event: SortChangedEvent): void {
console.log(event);
}
}

<next-grid> uses :host { display: block }, so give it an explicit CSS height.

  • Inputs: Every GridOptions<T> field except container is available as an input ([columnDefs], [rowData], [theme], [modules], etc.). Changes arrive via ngOnChanges, so pass new references rather than mutating objects/arrays in place.
  • Outputs: Every grid event is an output without the on prefix ((sortChanged), (modelUpdated), (selectionChanged)), except (gridError) (renamed from error so DOM element error events do not collide) and (gridReady) (emits Grid<T> once created).
  • grid Timing: The grid is created after the first browser render (null on the server and potentially null inside ngAfterViewInit / afterNextRender). Use (gridReady) to capture the live Grid<T> instance.
  • Development Warnings: Changing construction-only inputs logs a warning (@if/@for with a new track key recreates the grid). Define process.env.NODE_ENV: '"production"' in your Angular CLI define config to silence dev warnings in production builds.
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import type { CellRendererParams, ColumnDef } from 'next-grid-js/core';
import {
angularCellEditor,
angularCellRenderer,
type AngularCellEditorParams,
} from 'next-grid-angular';
@Component({
selector: 'order-total',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `<b>{{ params.value }}</b>`,
})
export class TotalComponent {
@Input({ required: true }) params!: CellRendererParams<Order>;
}
@Component({
selector: 'order-total-editor',
template: `<input
[value]="params.value"
(input)="params.setValue(+$any($event.target).value)"
(blur)="params.commit()"
/>`,
})
export class TotalEditorComponent {
@Input({ required: true }) params!: AngularCellEditorParams<Order>;
}
const columnDefs: ColumnDef<Order>[] = [
{
colId: 'total',
key: 'total',
isEditable: true,
cellRenderer: angularCellRenderer<Order>(TotalComponent),
cellEditor: angularCellEditor<Order>(TotalEditorComponent),
},
];
  • Components receive the <next-grid> element’s injector (services, router, environment providers) and support both @Input({ required: true }) params and params = input.required().
  • Zones & Change Detection: The grid runs outside NgZone so scrolling and resizing do not trigger change detection; subscribed outputs re-enter the zone automatically. Inside zone.js apps, run frequent GridApi calls inside NgZone.runOutsideAngular if needed, and drive async updates in renderers with signals, AsyncPipe, or markForCheck().
  • SSR: Renders an empty <next-grid> element on the server and mounts the grid only in the browser.