Documentation
This tutorial puts 100,000 rows in a grid and moves twenty of their prices every second. It covers the three things that keep such a page fast and tidy: let the grid virtualize, change cells instead of replacing the data, and clean up when the grid goes away.

Set up a page as in Bind the jQuery Grid to data. The grid sorts, filters from the column menu and resizes columns, so the page loads these files:
<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/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.columnsresize.js"></script>
The timings below were measured in Chromium on a desktop computer. Yours will differ; the proportions between them will not change much.
With a fixed height, the grid creates elements only for the rows in view (16 for this 520-pixel grid) and reuses them as you scroll, whatever the number of rows. autoheight makes the grid as tall as its rows, so it creates an element for every row: 2,001 for a 2,000-row table. Keep it for small tables, or use it with paging.
// A fixed height: the grid then creates elements only for the rows in view and reuses them
// as you scroll. (autoheight would create one for every row.)
grid.jqxGrid({
theme: 'fluent',
width: '100%',
height: 520,
source: new $.jqx.dataAdapter({
localdata: quotes,
datatype: 'array',
id: 'id',
datafields: [
{ name: 'id', type: 'number' },
{ name: 'symbol', type: 'string' },
{ name: 'exchange', type: 'string' },
{ name: 'price', type: 'number' },
{ name: 'change', type: 'number' },
{ name: 'volume', type: 'number' }
]
}),
sortable: true,
filterable: true,
columnsresize: true,
columns: [
{ text: 'Symbol', datafield: 'symbol', width: 140 },
{ text: 'Exchange', datafield: 'exchange', width: 110 },
{ text: 'Price', datafield: 'price', width: 120, cellsformat: 'f2', cellsalign: 'right', align: 'right' },
{
text: 'Change', datafield: 'change', width: 110, cellsformat: 'f2', cellsalign: 'right', align: 'right',
cellclassname: (row, field, value) => (value > 0 ? 'up' : value < 0 ? 'down' : '')
},
{ text: 'Volume', datafield: 'volume', cellsformat: 'n0', cellsalign: 'right', align: 'right' }
]
});
The rows are made once, before the grid is created. With 100,000 rows the grid is created in about 200 milliseconds and shows its first rows about a quarter of a second after the page's scripts have loaded. Sorting all the rows by price takes about 200 milliseconds, a filter on the symbol 10 to 15, and scrolling to the last row 20 to 35.
To change a few values, set the cells: setcellvalue for each changed cell, between beginupdate and endupdate so that the grid draws once. getrowboundindexbyid finds a row's index from its id, and getcellvalue reads the current value.
// Twenty of the watched rows change each second. Only the changed cells are set, inside one
// beginupdate/endupdate pair, so the grid draws once for all of them.
function tick() {
const started = performance.now();
grid.jqxGrid('beginupdate');
for (let n = 0; n < 20; n++) {
const id = String(1 + Math.floor(Math.random() * WATCHED));
const index = grid.jqxGrid('getrowboundindexbyid', id);
const change = Math.round((Math.random() - 0.5) * 200) / 100;
grid.jqxGrid('setcellvalue', index, 'price', Math.max(1, grid.jqxGrid('getcellvalue', index, 'price') + change));
grid.jqxGrid('setcellvalue', index, 'change', change);
}
grid.jqxGrid('endupdate');
lastUpdate.textContent = `20 rows updated in ${(performance.now() - started).toFixed(1)} ms`;
}
Measured with the 100,000 rows of this page, for twenty rows:
| Method | Time |
|---|---|
setcellvalue for each cell, inside beginupdate/endupdate | 5 to 25 ms |
updatebounddata (bind all the rows again) | about 300 ms |
updaterow for each row, inside beginupdate/endupdate | about 1.5 s |
updaterow for each row | about 3 s |
The Change column colours itself with cellclassname, which the grid calls again when a cell changes. Save the two classes as quotes.css next to the page:
.up { color: #15803d !important; }
.down { color: #b91c1c !important; }
A page that shows the grid for a while, such as one view of a single-page app, removes it when the view closes. Stop the timer first, then call destroy: it removes the grid and all its elements, the element the grid was created on included. Calls to the destroyed grid do nothing, so a timer left running would not fail; it would keep running for nothing.
// When the grid leaves the page (in a single-page app, when its view closes), stop the
// timer first, then destroy the grid: destroy removes the grid and its elements.
document.getElementById('remove').addEventListener('click', () => {
stopLive();
grid.jqxGrid('destroy');
liveButton.disabled = true;
});
To show the grid again, create a new element for it and create the grid on that.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Quotes</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">
<link rel="stylesheet" href="quotes.css">
<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/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.columnsresize.js"></script>
</head>
<body>
<main style="padding: 16px;">
<h1>Quotes</h1>
<p>
<span id="rowCount"></span>
<button id="live" type="button">Start live updates</button>
<button id="remove" type="button">Remove the grid</button>
<span id="lastUpdate" aria-live="off"></span>
</p>
<div id="grid"></div>
</main>
<script type="module">
const ROWS = 100_000;
// The live feed moves the prices of the first 200 symbols, the ones in view.
const WATCHED = 200;
const exchanges = ['NYSE', 'NASDAQ', 'LSE', 'XETRA', 'TSE'];
// 100,000 rows, made once.
const quotes = Array.from({ length: ROWS }, (_, i) => ({
id: i + 1,
symbol: `SYM${String(i + 1).padStart(6, '0')}`,
exchange: exchanges[i % exchanges.length],
price: Math.round((10 + ((i * 7919) % 99000) / 100) * 100) / 100,
change: 0,
volume: (i * 104729) % 5_000_000
}));
const grid = $('#grid');
// A fixed height: the grid then creates elements only for the rows in view and reuses them
// as you scroll. (autoheight would create one for every row.)
grid.jqxGrid({
theme: 'fluent',
width: '100%',
height: 520,
source: new $.jqx.dataAdapter({
localdata: quotes,
datatype: 'array',
id: 'id',
datafields: [
{ name: 'id', type: 'number' },
{ name: 'symbol', type: 'string' },
{ name: 'exchange', type: 'string' },
{ name: 'price', type: 'number' },
{ name: 'change', type: 'number' },
{ name: 'volume', type: 'number' }
]
}),
sortable: true,
filterable: true,
columnsresize: true,
columns: [
{ text: 'Symbol', datafield: 'symbol', width: 140 },
{ text: 'Exchange', datafield: 'exchange', width: 110 },
{ text: 'Price', datafield: 'price', width: 120, cellsformat: 'f2', cellsalign: 'right', align: 'right' },
{
text: 'Change', datafield: 'change', width: 110, cellsformat: 'f2', cellsalign: 'right', align: 'right',
cellclassname: (row, field, value) => (value > 0 ? 'up' : value < 0 ? 'down' : '')
},
{ text: 'Volume', datafield: 'volume', cellsformat: 'n0', cellsalign: 'right', align: 'right' }
]
});
document.getElementById('rowCount').textContent = `${ROWS.toLocaleString('en-US')} rows`;
const lastUpdate = document.getElementById('lastUpdate');
const liveButton = document.getElementById('live');
// Twenty of the watched rows change each second. Only the changed cells are set, inside one
// beginupdate/endupdate pair, so the grid draws once for all of them.
function tick() {
const started = performance.now();
grid.jqxGrid('beginupdate');
for (let n = 0; n < 20; n++) {
const id = String(1 + Math.floor(Math.random() * WATCHED));
const index = grid.jqxGrid('getrowboundindexbyid', id);
const change = Math.round((Math.random() - 0.5) * 200) / 100;
grid.jqxGrid('setcellvalue', index, 'price', Math.max(1, grid.jqxGrid('getcellvalue', index, 'price') + change));
grid.jqxGrid('setcellvalue', index, 'change', change);
}
grid.jqxGrid('endupdate');
lastUpdate.textContent = `20 rows updated in ${(performance.now() - started).toFixed(1)} ms`;
}
let timer = null;
function stopLive() {
clearInterval(timer);
timer = null;
liveButton.textContent = 'Start live updates';
}
liveButton.addEventListener('click', () => {
if (timer) {
stopLive();
} else {
timer = setInterval(tick, 1000);
liveButton.textContent = 'Stop live updates';
}
});
// When the grid leaves the page (in a single-page app, when its view closes), stop the
// timer first, then destroy the grid: destroy removes the grid and its elements.
document.getElementById('remove').addEventListener('click', () => {
stopLive();
grid.jqxGrid('destroy');
liveButton.disabled = true;
});
</script>
</body>
</html>
The grid opens at once with 100,000 rows, and scrolling, sorting and filtering work on all of them. Start live updates moves twenty of the first two hundred prices each second, and the line next to the button gives the time each update took. Remove the grid stops the updates and removes the grid.