Documentation
This tutorial shows the two ways to give jqxGrid its rows in plain JavaScript: let the grid's data adapter load a URL, or load the data yourself with fetch and hand the rows to the grid. You will also add and remove rows with the grid's methods, and replace all of them with a new data set.
It is the first of a series of jqxGrid tutorials for JavaScript. Each one is a single HTML page that you can save and open. None of them needs jQuery or a build step.

The examples load jQWidgets 27 from the jsDelivr CDN: the base stylesheet, a theme (fluent here), jqxcore.js, and then only the files the page uses. jqxcore.js provides $, so $('#grid').jqxGrid({ … }) works on a page without jQuery. The pages of this tutorial load these files:
<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/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/jqxcheckbox.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>
| File | What it adds |
|---|---|
jqxcore.js | The core of every widget, and $ |
jqxdata.js | The data adapter, $.jqx.dataAdapter |
jqxbuttons.js, jqxscrollbar.js | The grid's scroll bars |
jqxcheckbox.js | The checkbox column |
jqxgrid.js, jqxgrid.selection.js | The grid and its row and cell selection (needed even when the page selects nothing) |
A missing file usually stops the grid with an error that names it, such as jqxGrid: Missing reference to jqxscrollbar.js. Two do not: without jqxcheckbox.js the checkbox column stays empty, and without jqxdatetimeinput.js (used from the next tutorial on) the date filter is missing. The later tutorials list the files they add.
To install from npm instead, run npm install jqwidgets-scripts and replace https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/ with node_modules/jqwidgets-scripts/ in the same tags. With a bundler such as Vite, import the library and the styles as shown on the documentation home page.
Open the pages through a web server, not as files: a page opened from a file:// address cannot fetch other files. Any static server works. With Node.js installed, run this in the folder of the pages and open the address it prints:
npx serve
The examples use this sample file. Save it as products.json next to the pages:
[
{
"id": 1,
"name": "Chai",
"category": "Beverages",
"price": 18,
"inStock": true
},
{
"id": 2,
"name": "Chang",
"category": "Condiments",
"price": 19,
"inStock": true
},
{
"id": 3,
"name": "Aniseed Syrup",
"category": "Confections",
"price": 10,
"inStock": false
},
{
"id": 4,
"name": "Ikura",
"category": "Dairy",
"price": 31,
"inStock": true
},
{
"id": 5,
"name": "Konbu",
"category": "Seafood",
"price": 6,
"inStock": true
},
{
"id": 6,
"name": "Tofu",
"category": "Beverages",
"price": 23.25,
"inStock": true
},
{
"id": 7,
"name": "Pavlova",
"category": "Condiments",
"price": 17.45,
"inStock": false
},
{
"id": 8,
"name": "Mascarpone",
"category": "Confections",
"price": 32,
"inStock": true
}
]
A $.jqx.dataAdapter describes where the rows come from and the type of each field. Given a url, it loads the rows itself when the grid asks for them. The grid is created by calling jqxGrid with its options on an empty element:
// The adapter loads the URL itself, when the grid asks for its data.
const source = new $.jqx.dataAdapter(
{
url: 'products.json',
datatype: 'json',
id: 'id',
datafields: [
{ name: 'name', type: 'string' },
{ name: 'category', type: 'string' },
{ name: 'price', type: 'number' },
{ name: 'inStock', type: 'bool' }
]
},
{
loadError: (xhr, status, error) => {
document.getElementById('status').textContent = `Could not load the products (${status}: ${error}).`;
}
}
);
$('#grid').jqxGrid({
theme: 'fluent',
width: '100%',
autoheight: true,
source,
columns: [
{ text: 'Product', datafield: 'name', width: 220 },
{ text: 'Category', datafield: 'category', width: 160 },
{ text: 'Price', datafield: 'price', cellsformat: 'c2', cellsalign: 'right', align: 'right', width: 110 },
{ text: 'In stock', datafield: 'inStock', columntype: 'checkbox', width: 90 }
]
});
The datafields types matter: a number field sorts and formats as a number (cellsformat: 'c2' writes it as currency), and a bool field fills the checkbox column. id: 'id' names the field that identifies a row, which methods such as deleterow and getrowdatabyid use.
When the request fails, the adapter calls loadError with the request, a status and the error. For an HTTP error the status is error and the error is the status text (Not Found, Internal Server Error); for an answer that is not valid JSON the status is parsererror. The adapter adds the grid's state to the URL as query parameters (pagenum, pagesize, filterscount, and a _ parameter that keeps the browser from answering from its cache). A static file ignores them; server-side processing uses them.
When the page needs the rows too (to count them, show them elsewhere, or change them before they are shown), load them with fetch and give the adapter the array as localdata. The page's script is a module (<script type="module">), so it can await at the top level, and it runs after the page's elements exist.
// Load the rows. A failed request throws, with the reason in its message.
async function loadProducts() {
const response = await fetch('products.json');
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
return response.json();
}
let products = [];
try {
products = await loadProducts();
} catch (error) {
status.textContent = `Could not load the products: ${error.message}`;
}
// The source keeps the settings; the grid reads its rows from localdata.
const source = {
localdata: products,
datatype: 'array',
id: 'id',
datafields: [
{ name: 'id', type: 'number' },
{ name: 'name', type: 'string' },
{ name: 'category', type: 'string' },
{ name: 'price', type: 'number' },
{ name: 'inStock', type: 'bool' }
]
};
grid.jqxGrid({
theme: 'fluent',
width: '100%',
autoheight: true,
source: new $.jqx.dataAdapter(source),
columns: [
{ text: 'Product', datafield: 'name', width: 220 },
{ text: 'Category', datafield: 'category', width: 160 },
{ text: 'Price', datafield: 'price', cellsformat: 'c2', cellsalign: 'right', align: 'right', width: 110 },
{ text: 'In stock', datafield: 'inStock', columntype: 'checkbox', width: 90 }
]
});
A failed request ends in the catch; the page writes the message with textContent and the grid shows an empty table.
A grid method is called as $('#grid').jqxGrid('method', arguments…). addrow takes the new row's id and its data; deleterow takes an id or an array of ids. getrows returns the rows the grid holds, each with a uid, which is the row's id when the source names an id field.
// Add and remove rows with the grid's methods.
document.getElementById('add').addEventListener('click', () => {
const rows = grid.jqxGrid('getrows');
const id = Math.max(0, ...rows.map((row) => row.id)) + 1;
grid.jqxGrid('addrow', id, { id, name: `New product ${id}`, category: 'Beverages', price: 9.5, inStock: true });
showCount();
});
document.getElementById('removeOutOfStock').addEventListener('click', () => {
const ids = grid.jqxGrid('getrows').filter((row) => !row.inStock).map((row) => row.uid);
grid.jqxGrid('deleterow', ids);
showCount();
});
When the data set itself changes, put the new rows in the source's localdata and call updatebounddata: the grid binds to them again. The source here is the settings object the adapter was made from, kept in a constant for that purpose.
// A new data set: put it in the source and bind the grid to it again.
document.getElementById('reload').addEventListener('click', async () => {
try {
source.localdata = await loadProducts();
grid.jqxGrid('updatebounddata');
status.textContent = '';
} catch (error) {
status.textContent = `Could not load the products: ${error.message}`;
}
showCount();
});
To change a few values in rows the grid already shows, set the cells instead (setcellvalue); Large data sets and live updates measures how much faster that is.
Save it as data-binding.html next to products.json:
<!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/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/jqxcheckbox.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>
</head>
<body>
<main style="padding: 16px;">
<h1>Products</h1>
<p id="status" role="alert"></p>
<p>
<button id="add" type="button">Add a product</button>
<button id="removeOutOfStock" type="button">Remove products not in stock</button>
<button id="reload" type="button">Reload</button>
<span id="count"></span>
</p>
<div id="grid"></div>
</main>
<script type="module">
const grid = $('#grid');
const status = document.getElementById('status');
const count = document.getElementById('count');
// Load the rows. A failed request throws, with the reason in its message.
async function loadProducts() {
const response = await fetch('products.json');
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
return response.json();
}
let products = [];
try {
products = await loadProducts();
} catch (error) {
status.textContent = `Could not load the products: ${error.message}`;
}
// The source keeps the settings; the grid reads its rows from localdata.
const source = {
localdata: products,
datatype: 'array',
id: 'id',
datafields: [
{ name: 'id', type: 'number' },
{ name: 'name', type: 'string' },
{ name: 'category', type: 'string' },
{ name: 'price', type: 'number' },
{ name: 'inStock', type: 'bool' }
]
};
grid.jqxGrid({
theme: 'fluent',
width: '100%',
autoheight: true,
source: new $.jqx.dataAdapter(source),
columns: [
{ text: 'Product', datafield: 'name', width: 220 },
{ text: 'Category', datafield: 'category', width: 160 },
{ text: 'Price', datafield: 'price', cellsformat: 'c2', cellsalign: 'right', align: 'right', width: 110 },
{ text: 'In stock', datafield: 'inStock', columntype: 'checkbox', width: 90 }
]
});
function showCount() {
count.textContent = `${grid.jqxGrid('getdatainformation').rowscount} products`;
}
showCount();
// Add and remove rows with the grid's methods.
document.getElementById('add').addEventListener('click', () => {
const rows = grid.jqxGrid('getrows');
const id = Math.max(0, ...rows.map((row) => row.id)) + 1;
grid.jqxGrid('addrow', id, { id, name: `New product ${id}`, category: 'Beverages', price: 9.5, inStock: true });
showCount();
});
document.getElementById('removeOutOfStock').addEventListener('click', () => {
const ids = grid.jqxGrid('getrows').filter((row) => !row.inStock).map((row) => row.uid);
grid.jqxGrid('deleterow', ids);
showCount();
});
// A new data set: put it in the source and bind the grid to it again.
document.getElementById('reload').addEventListener('click', async () => {
try {
source.localdata = await loadProducts();
grid.jqxGrid('updatebounddata');
status.textContent = '';
} catch (error) {
status.textContent = `Could not load the products: ${error.message}`;
}
showCount();
});
</script>
</body>
</html>
Open it through the web server. The grid shows the eight products and the line above it reads 8 products. Add a product adds New product 9; Remove products not in stock removes Aniseed Syrup and Pavlova; Reload loads the file again and shows its eight products.