Angular
next-grid-angular wraps next-grid-js/core as a standalone <next-grid> component supporting both zoneless Angular applications and zone.js.
Installation
Section titled “Installation”npm install next-grid-angular next-grid-jsPeers: 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, Outputs & Creation Timing
Section titled “Inputs, Outputs & Creation Timing”- Inputs: Every
GridOptions<T>field exceptcontaineris available as an input ([columnDefs],[rowData],[theme],[modules], etc.). Changes arrive viangOnChanges, so pass new references rather than mutating objects/arrays in place. - Outputs: Every grid event is an output without the
onprefix ((sortChanged),(modelUpdated),(selectionChanged)), except(gridError)(renamed fromerrorso DOM elementerrorevents do not collide) and(gridReady)(emitsGrid<T>once created). gridTiming: The grid is created after the first browser render (nullon the server and potentiallynullinsidengAfterViewInit/afterNextRender). Use(gridReady)to capture the liveGrid<T>instance.- Development Warnings: Changing construction-only inputs logs a warning (
@if/@forwith a newtrackkey recreates the grid). Defineprocess.env.NODE_ENV: '"production"'in your Angular CLIdefineconfig to silence dev warnings in production builds.
Cell Renderers & Editors
Section titled “Cell Renderers & Editors”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 }) paramsandparams = input.required(). - Zones & Change Detection: The grid runs outside
NgZoneso scrolling and resizing do not trigger change detection; subscribed outputs re-enter the zone automatically. Insidezone.jsapps, run frequentGridApicalls insideNgZone.runOutsideAngularif needed, and drive async updates in renderers with signals,AsyncPipe, ormarkForCheck(). - SSR: Renders an empty
<next-grid>element on the server and mounts the grid only in the browser.