Angular UI Components Documentation
This tutorial exports the grid's rows to Excel, CSV, PDF and JSON files, and remembers the grid's layout (sort, filters, page, column widths and order) in the browser, so it is back the next time the page opens.

Use an Angular CLI app set up as in Angular CLI with jQWidgets. Excel export needs JSZip:
npm install jszip
exportdata(type, fileName) builds the file in the browser and downloads it. The types include xlsx, csv, tsv, pdf, json, xml and html. The file holds every row as the grid sorts and filters it, not only the current page, with the values formatted as the cells show them (a number column without a cellsformat is written with two decimals, 79.00).
export class App {
// …
// The rows as the grid shows them now (sorted and filtered), in a file.
exportAs(type: 'xlsx' | 'csv' | 'pdf' | 'json'): void {
this.grid().exportdata(type, 'products');
}
// …
}
The grid component of jqwidgets-ng already contains the exporter. Excel files also need JSZip, which the exporter looks for as a global; without it, the Excel button logs Missing reference to 'jszip.min.js'. and downloads nothing. Import it at the top of app.ts and put it on window:
// Excel (xlsx) export builds the file with JSZip, which the grid looks for as a global.
import JSZip from 'jszip';
(window as unknown as { JSZip: typeof JSZip }).JSZip = JSZip;
JSZip is a CommonJS package, and ng build warns about it (Module 'jszip' used by 'src/app/app.ts' is not ESM). Tell the build that it is expected, in the options of the build target in angular.json:
"allowedCommonJsDependencies": [
"jszip"
]
For a printout, window.print() prints the page; exportdata('html', …) gives a file with the grid's rows as an HTML table, if you prefer to print only those.
savestate() returns the grid's layout as an object, and loadstate(state) puts it back. The component saves it to localStorage each time the user sorts, filters, pages, or resizes or moves a column:
export class App {
// …
// Sorting, filtering, paging, a resized or moved column: the layout is saved each time.
saveState(): void {
if (this.loading) {
return;
}
const state = this.grid().savestate();
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(state));
this.saved.set(new Date().toLocaleTimeString());
} catch {
// storage full or blocked (private window): the grid works without it
}
}
// …
}
It puts the layout back once the grid exists. afterNextRender runs after Angular has rendered the component for the first time, when the grid has been created and bound to its data:
export class App {
// …
// The layout the grid starts with, for "Reset the layout".
private initialLayout: jqwidgets.GridGetState | null = null;
// loadstate raises sort, filter and page events while it puts a layout back, before it
// is done. Those must not be saved.
private loading = false;
constructor() {
// Once the grid exists: keep its first layout, then put back the one of the last visit.
afterNextRender(() => {
this.initialLayout = this.grid().savestate();
let state: unknown = null;
try {
state = JSON.parse(localStorage.getItem(STORAGE_KEY) ?? 'null');
} catch {
// ignore a damaged or unreadable entry
}
if (state) {
this.load(state);
}
});
}
private load(state: unknown): void {
this.loading = true;
try {
this.grid().loadstate(state);
} finally {
this.loading = false;
}
}
// …
}
The loading flag matters. loadstate raises the same sort, filter and pagechanged events while it puts the layout back, before it is done. Saved at that moment, the layout lost its sort: in a test without the flag, the grid was still sorted after one reload and no longer sorted after the second.
Storage can fail (a private window, a full quota, a blocked site), so every access is in a try block: the grid works without it. Reset the layout puts back the layout the grid started with, column widths and order included, and then removes the saved one. To keep a user's layout across devices, send the same object to your server instead.
src/app/app.ts:
import { afterNextRender, Component, signal, viewChild } from '@angular/core';
import { jqxGridComponent, jqxGridModule } from 'jqwidgets-ng/jqxgrid';
// Excel (xlsx) export builds the file with JSZip, which the grid looks for as a global.
import JSZip from 'jszip';
(window as unknown as { JSZip: typeof JSZip }).JSZip = JSZip;
interface Product {
id: number;
name: string;
category: string;
price: number;
stock: number;
}
const categories = ['Beverages', 'Condiments', 'Confections', 'Dairy', 'Seafood'];
const names = [
'Chai',
'Chang',
'Aniseed Syrup',
'Ikura',
'Konbu',
'Tofu',
'Pavlova',
'Teatime Biscuits',
'Mascarpone',
'Gnocchi',
'Inlagd Sill',
'Gravad lax'
];
const products: Product[] = Array.from({ length: 60 }, (_, i) => ({
id: i + 1,
name: `${names[i % names.length]} ${Math.floor(i / names.length) + 1}`,
category: categories[(i * 3) % categories.length],
price: Math.round((3 + ((i * 37) % 60) + ((i * 13) % 100) / 100) * 100) / 100,
stock: (i * 17) % 120
}));
const STORAGE_KEY = 'products-grid-state';
@Component({ selector: 'app-root', imports: [jqxGridModule], templateUrl: './app.html' })
export class App {
readonly grid = viewChild.required<jqxGridComponent>('grid');
readonly saved = signal<string | null>(null);
readonly source = new jqx.dataAdapter({
localdata: products,
datatype: 'array',
id: 'id',
datafields: [
{ name: 'name', type: 'string' },
{ name: 'category', type: 'string' },
{ name: 'price', type: 'number' },
{ name: 'stock', type: 'number' }
]
});
readonly columns: jqwidgets.GridColumn[] = [
{ text: 'Product', datafield: 'name', width: 220 },
{ text: 'Category', datafield: 'category', width: 150 },
{
text: 'Price',
datafield: 'price',
width: 110,
cellsformat: 'c2',
cellsalign: 'right',
align: 'right'
},
{ text: 'In stock', datafield: 'stock', cellsalign: 'right', align: 'right' }
];
// The layout the grid starts with, for "Reset the layout".
private initialLayout: jqwidgets.GridGetState | null = null;
// loadstate raises sort, filter and page events while it puts a layout back, before it
// is done. Those must not be saved.
private loading = false;
constructor() {
// Once the grid exists: keep its first layout, then put back the one of the last visit.
afterNextRender(() => {
this.initialLayout = this.grid().savestate();
let state: unknown = null;
try {
state = JSON.parse(localStorage.getItem(STORAGE_KEY) ?? 'null');
} catch {
// ignore a damaged or unreadable entry
}
if (state) {
this.load(state);
}
});
}
private load(state: unknown): void {
this.loading = true;
try {
this.grid().loadstate(state);
} finally {
this.loading = false;
}
}
// Sorting, filtering, paging, a resized or moved column: the layout is saved each time.
saveState(): void {
if (this.loading) {
return;
}
const state = this.grid().savestate();
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(state));
this.saved.set(new Date().toLocaleTimeString());
} catch {
// storage full or blocked (private window): the grid works without it
}
}
resetLayout(): void {
this.load(this.initialLayout);
try {
localStorage.removeItem(STORAGE_KEY);
} catch {
// nothing saved
}
this.saved.set(null);
}
// The rows as the grid shows them now (sorted and filtered), in a file.
exportAs(type: 'xlsx' | 'csv' | 'pdf' | 'json'): void {
this.grid().exportdata(type, 'products');
}
print(): void {
window.print();
}
}
src/app/app.html:
<h1>Products</h1>
<p>
Export:
<button type="button" (click)="exportAs('xlsx')">Excel</button>
<button type="button" (click)="exportAs('csv')">CSV</button>
<button type="button" (click)="exportAs('pdf')">PDF</button>
<button type="button" (click)="exportAs('json')">JSON</button>
<button type="button" (click)="print()">Print</button>
</p>
<p>
<button type="button" (click)="resetLayout()">Reset the layout</button>
<span aria-live="polite">
@if (saved(); as time) {
Layout saved at {{ time }}
} @else {
Sort, filter or resize: the layout is kept for your next visit.
}
</span>
</p>
<jqxGrid #grid
[theme]="'fluent'"
[width]="'100%'"
[autoheight]="true"
[source]="source"
[columns]="columns"
[sortable]="true"
[filterable]="true"
[showfilterrow]="true"
[pageable]="true"
[columnsresize]="true"
[columnsreorder]="true"
(onSort)="saveState()"
(onFilter)="saveState()"
(onPagechanged)="saveState()"
(onPagesizechanged)="saveState()"
(onColumnresized)="saveState()"
(onColumnreordered)="saveState()">
</jqxGrid>
Click the Price header twice and then Excel: products.xlsx holds all 60 products, the most expensive (Gravad lax 4, $62.11) first. Reload the page: the grid is still sorted by price. Reset the layout forgets it.