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.

Set up a page as in Bind the jQuery Grid to data. Besides the files for sorting, filtering and paging (without jqxcheckbox.js and the date files, which its text filters do not need), this page loads the export and storage modules, the column resize and reorder modules, and JSZip, which the Excel export uses to build the file:
<script src="https://cdn.jsdelivr.net/npm/jszip@3/dist/jszip.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxcore.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxdata.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxdata.export.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxexport.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxbuttons.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxscrollbar.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxmenu.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxlistbox.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxdropdownlist.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.selection.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.sort.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.filter.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.pager.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.columnsresize.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.columnsreorder.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.storage.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.export.js"></script>
jqxdata.export.js and jqxgrid.export.js are needed for every file type. Excel files also need jqxexport.js and JSZip; without them only the Excel export fails, with Missing reference to 'jszip.min.js' or, for jqxexport.js, DataExporter is not a constructor. jqxgrid.storage.js saves and loads the layout.
exportdata(type, fileName) builds the file in the browser and downloads it. The types are 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.
// The rows as the grid shows them now (sorted and filtered), in a file.
for (const button of document.querySelectorAll('[data-export]')) {
button.addEventListener('click', () => grid.jqxGrid('exportdata', button.dataset.export, 'products'));
}
The values are written as the cells show them: in CSV the price is "$62.11". In Excel files numbers stay numbers, with the column's format ($#,0.00), so they can be summed. A number column without a cellsformat is written with two decimals (79.00) in the text formats, which is why the In stock column has cellsformat: 'n0'.
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.
getstate returns the grid's layout as a plain object: the sort, the page and page size, the filters, the selected rows, the groups, and each column's width, position and visibility. loadstate(state) puts it back. The example keeps the layout the page starts with, then puts back the layout of the last visit from localStorage:
// The layout the page starts with, for "Reset the layout".
const initialState = grid.jqxGrid('getstate');
// Put back the state of the last visit.
let state = null;
try {
state = JSON.parse(localStorage.getItem(STORAGE_KEY) ?? 'null');
} catch {
// ignore a damaged or unreadable entry
}
if (state) {
grid.jqxGrid('loadstate', state);
}
It saves the layout each time the user sorts, filters, pages, or resizes or moves a column:
// Sorting, filtering, paging, a resized or moved column: the grid's state is saved each time.
grid.on('sort filter pagechanged pagesizechanged columnresized columnreordered', () => {
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(grid.jqxGrid('getstate')));
saved.textContent = `Layout saved at ${new Date().toLocaleTimeString()}`;
} catch {
// storage full or blocked (private window): the grid works without it
}
});
Use getstate rather than savestate here. savestate returns the same object, but also writes it to localStorage under a key of its own (jqxGrid followed by the element's id), and throws when the browser blocks storage. Storage can fail (a private window, a full quota, a blocked site), so every access in the example is in a try block, and the grid works without it. To keep a user's layout across devices, send the same object to your server instead.
Reset the layout loads the layout the page started with, column widths included, and forgets the saved one:
document.getElementById('reset').addEventListener('click', () => {
grid.jqxGrid('loadstate', initialState);
try {
localStorage.removeItem(STORAGE_KEY);
} catch {
// nothing saved
}
saved.textContent = 'Sort, filter or resize: the layout is kept for your next visit.';
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Products</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/styles/jqx.base.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/styles/jqx.fluent.css">
<script src="https://cdn.jsdelivr.net/npm/jszip@3/dist/jszip.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxcore.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxdata.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxdata.export.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxexport.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxbuttons.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxscrollbar.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxmenu.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxlistbox.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxdropdownlist.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.selection.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.sort.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.filter.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.pager.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.columnsresize.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.columnsreorder.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.storage.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.export.js"></script>
</head>
<body>
<main style="padding: 16px;">
<h1>Products</h1>
<p>
Export:
<button type="button" data-export="xlsx">Excel</button>
<button type="button" data-export="csv">CSV</button>
<button type="button" data-export="pdf">PDF</button>
<button type="button" data-export="json">JSON</button>
<button id="print" type="button">Print</button>
</p>
<p>
<button id="reset" type="button">Reset the layout</button>
<span id="saved" aria-live="polite">Sort, filter or resize: the layout is kept for your next visit.</span>
</p>
<div id="grid"></div>
</main>
<script type="module">
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 = 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 grid = $('#grid');
grid.jqxGrid({
theme: 'fluent',
width: '100%',
autoheight: true,
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' }
]
}),
sortable: true,
filterable: true,
showfilterrow: true,
pageable: true,
columnsresize: true,
columnsreorder: true,
columns: [
{ 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', cellsformat: 'n0', cellsalign: 'right', align: 'right' }
]
});
const STORAGE_KEY = 'products-grid-state';
const saved = document.getElementById('saved');
// The layout the page starts with, for "Reset the layout".
const initialState = grid.jqxGrid('getstate');
// Put back the state of the last visit.
let state = null;
try {
state = JSON.parse(localStorage.getItem(STORAGE_KEY) ?? 'null');
} catch {
// ignore a damaged or unreadable entry
}
if (state) {
grid.jqxGrid('loadstate', state);
}
// Sorting, filtering, paging, a resized or moved column: the grid's state is saved each time.
grid.on('sort filter pagechanged pagesizechanged columnresized columnreordered', () => {
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(grid.jqxGrid('getstate')));
saved.textContent = `Layout saved at ${new Date().toLocaleTimeString()}`;
} catch {
// storage full or blocked (private window): the grid works without it
}
});
document.getElementById('reset').addEventListener('click', () => {
grid.jqxGrid('loadstate', initialState);
try {
localStorage.removeItem(STORAGE_KEY);
} catch {
// nothing saved
}
saved.textContent = 'Sort, filter or resize: the layout is kept for your next visit.';
});
// The rows as the grid shows them now (sorted and filtered), in a file.
for (const button of document.querySelectorAll('[data-export]')) {
button.addEventListener('click', () => grid.jqxGrid('exportdata', button.dataset.export, 'products'));
}
document.getElementById('print').addEventListener('click', () => window.print());
</script>
</body>
</html>
Click the Price header twice to sort from the most expensive product, and click Excel: products.xlsx holds all 60 products, the most expensive first. Type chai in the Product filter and drag the border between two headers to widen a column, then reload the page: the sort, the filter and the width are back. Reset the layout returns to the start.
exportdata, getstate and loadstate in the jQuery Grid API reference