Angular UI Components Documentation
A grid cell can hold any Angular component: a button, a badge, a chart or a form control, with its inputs, outputs and change detection working as they do anywhere else in the app. This guide shows a column whose cells are an Angular component, created with Angular's createComponent function, and reused as the user pages and scrolls.
This page used to load components with ComponentFactoryResolver in an Angular app with an NgModule. That API has been deprecated since Angular 13; the createComponent function (Angular 14.1 and later) creates a component directly from its class. The code below is a standalone Angular 22 app with signal inputs and outputs.
A jqxGrid column with createwidget puts custom content in its cells. The grid only builds the cells that are visible, and reuses them:
createwidget(row, column, value, element) runs once for each cell element the grid creates. Put your component into element.initwidget(row, column, value, element) runs when a cell element shows another row, for example after the user changes the page. Update the component with the new value. The grid requires this callback whenever createwidget is set.destroywidget(widget) runs when the grid removes the cell element. Destroy the component there.cellComponents creates the component in the cell element with createComponent, attaches it to the application so change detection reaches it, and keeps one component per cell element. bind sets the component's inputs for a row; create runs once per component, the place to subscribe to its outputs.
// src/app/cell-components.ts
import { ApplicationRef, ComponentRef, EnvironmentInjector, Type, createComponent, inject } from '@angular/core';
// Angular components in jqxGrid cells. The grid creates a widget for each visible
// cell once (createwidget), gives it another row as the user scrolls or pages
// (initwidget), and removes it when the grid no longer needs it (destroywidget).
// Spread the returned callbacks into a column. Call it in an injection context
// (a field initializer or the constructor).
export function cellComponents<C>(
component: Type<C>,
options: {
bind: (ref: ComponentRef<C>, value: unknown, row: number) => void;
create?: (ref: ComponentRef<C>) => void;
}
) {
const appRef = inject(ApplicationRef);
const environmentInjector = inject(EnvironmentInjector);
const refs = new Map<Element, ComponentRef<C>>();
return {
createwidget: (row: number, column: string, value: unknown, element: HTMLElement): void => {
const ref = createComponent(component, { environmentInjector, hostElement: element });
appRef.attachView(ref.hostView); // change detection, like any component in the app
refs.set(element, ref);
options.create?.(ref);
options.bind(ref, value, row);
},
initwidget: (row: number, column: string, value: unknown, element: HTMLElement): void => {
const ref = refs.get(element);
if (ref) options.bind(ref, value, row);
},
destroywidget: (widget: ArrayLike<Element>): void => {
const element = widget[0];
const ref = refs.get(element);
if (!ref) return;
appRef.detachView(ref.hostView);
ref.destroy();
refs.delete(element);
}
};
}
hostElement makes the cell element the component's host, so nothing extra is added to the grid's markup. inject needs an injection context, so call cellComponents in a field initializer or the constructor, as below.
Any standalone component works. This one shows a hero's name as a button and reports clicks through an output:
// src/app/hero-button.ts
import { Component, input, output } from '@angular/core';
// An ordinary standalone component, shown in a grid cell.
@Component({
selector: 'app-hero-button',
template: `<button type="button" class="hero" (click)="picked.emit(name())">
{{ name() }}
</button>`,
styles: [
`
.hero {
width: 100%;
height: 100%;
border: 0;
background: none;
color: #1b6f9c;
font: inherit;
text-align: left;
cursor: pointer;
}
.hero:hover {
text-decoration: underline;
}
`
]
})
export class HeroButton {
readonly name = input.required<string>();
readonly picked = output<string>();
}
Spread the callbacks into the column. bind passes the cell value to the component's name input with setInput, which also works for signal inputs; create subscribes to its picked output and writes to a signal that the template shows.
// src/app/app.ts
import { Component, signal } from '@angular/core';
import { jqxGridModule } from 'jqwidgets-ng/jqxgrid';
import { cellComponents } from './cell-components';
import { HeroButton } from './hero-button';
const HEROES = [
{ id: 11, name: 'Mr. Nice' },
{ id: 12, name: 'Narco' },
{ id: 13, name: 'Bombasto' },
{ id: 14, name: 'Celeritas' },
{ id: 15, name: 'Magneta' },
{ id: 16, name: 'RubberMan' },
{ id: 17, name: 'Dynama' },
{ id: 18, name: 'Dr IQ' },
{ id: 19, name: 'Magma' },
{ id: 20, name: 'Tornado' }
];
@Component({
selector: 'app-root',
imports: [jqxGridModule],
template: `
<h1>Heroes</h1>
<jqxGrid
[width]="'100%'"
[autoheight]="true"
[pageable]="true"
[pagesize]="5"
[source]="dataAdapter"
[columns]="columns"
>
</jqxGrid>
<p class="message">{{ message() }}</p>
`
})
export class App {
readonly message = signal('Pick a hero.');
private readonly heroCells = cellComponents(HeroButton, {
create: (ref: any) =>
ref.instance.picked.subscribe((name: any) => this.message.set(`You picked ${name}.`)),
bind: (ref: any, value: any) => ref.setInput('name', String(value))
});
readonly dataAdapter = new jqx.dataAdapter({
localdata: HEROES,
datatype: 'array',
datafields: [
{ name: 'id', type: 'number' },
{ name: 'name', type: 'string' }
]
});
readonly columns: jqwidgets.GridColumn[] = [
{ text: 'Id', datafield: 'id', width: 80 },
{ text: 'Hero', datafield: 'name', ...this.heroCells }
];
}
// src/main.ts
import { bootstrapApplication } from '@angular/platform-browser';
import { App } from './app';
bootstrapApplication(App).catch(err => console.error(err));
With five rows per page, the grid creates five HeroButton components. Going to the second page doesn't create new ones: initwidget gives the same five components the names of heroes 16 to 20, and clicking one reports the hero it now shows.
setInput on a signal input, signal.set in the output handler) schedule change detection by themselves, with or without zone.js.createComponent live until you destroy them; destroywidget does that when the grid removes a cell.cellsrenderer that returns an HTML string is lighter. Use components when a cell needs Angular features: inputs, outputs, other components, dependency injection.columns, createwidget, initwidget