Documentation
This tutorial changes how cells look: a coloured badge for a task's status, a progress bar, a red due date when a task is late, and a button in each row that opens the task. It also shows how to keep text that users typed from being read as HTML, which in jqxGrid matters for plain columns too.

Set up a page as in Bind the jQuery Grid to data. Renderers, cell classes and template columns are part of the grid itself, so the page loads the same files as a plain grid:
<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/jqxgrid.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.selection.js"></script>
jqxGrid writes a cell's value into the page as HTML. That is true in columns without a renderer as well: in jqwidgets-scripts 27.1.0 and earlier, a value such as <b>bold</b> in a plain text column shows in bold, and an <img> with an onerror attribute runs its script. The grid's enableSanitize option stops such a script, but it escapes that value twice, so the cell shows <img src=… instead of what the user typed.
So give every column that shows text from users a renderer that escapes it. A column's cellsrenderer receives the row index, the field and the value, and returns the cell's HTML:
// Cell renderers return HTML. Text that users typed goes through escapeHtml first:
// the third task's title would otherwise be markup.
function escapeHtml(text) {
return String(text).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
}
// A cell that shows its value as text. The grid writes values into the page as HTML,
// in columns without a renderer too, so every column of user text gets this renderer.
const textCell = (row, field, value) => `<div class="text-cell">${escapeHtml(value)}</div>`;
A renderer replaces the cell's content, including the element the grid puts around the value for alignment and padding. The text-cell class gives the text back its padding, and a line height equal to the grid's rowsheight (40 pixels here) centres it vertically. The third task has <script> in its title and shows it as text.
Renderers can return any HTML: the status column returns a badge, the progress column a bar. Values that come from the data still go through escapeHtml, and numbers through Number:
// Status: a badge, coloured by a class for each status.
const statusColumn = {
text: 'Status', datafield: 'status', width: 120,
cellsrenderer: (row, field, value) => `<span class="status ${statusClass[value] ?? ''}">${escapeHtml(value)}</span>`
};
// Progress: a bar. The value goes through Number, so only a number reaches the HTML.
const progressColumn = {
text: 'Progress', datafield: 'progress', width: 150,
cellsrenderer: (row, field, value) => {
const percent = Number(value);
return `<div class="progress" role="progressbar" aria-valuenow="${percent}" aria-valuemin="0" aria-valuemax="100"><div style="width: ${percent}%"></div><span>${percent}%</span></div>`;
}
};
The badge, the bar and the other cell styles are in a stylesheet. Save it as tasks.css next to the page:
.text-cell { padding: 0 6px; line-height: 40px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { display: inline-block; margin: 10px 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.status-open { background: #e0e7ff; color: #3730a3; }
.status-progress { background: #fef3c7; color: #92400e; }
.status-blocked { background: #fee2e2; color: #991b1b; }
.status-done { background: #dcfce7; color: #166534; }
.progress { position: relative; height: 18px; margin: 11px 8px; border-radius: 9px; background: #e5e7eb; overflow: hidden; }
.progress > div { height: 100%; background: #0f6cbd; }
.progress > span { position: absolute; inset: 0; text-align: center; font-size: 12px; line-height: 18px; color: #111827; }
.overdue { color: #b91c1c !important; font-weight: 600; }
.open-task { margin: 6px; padding: 4px 12px; cursor: pointer; }
cellclassname returns a class for one cell, from its value and its row. The due date of a task that is not done and is due before today gets the overdue class. Prefer it to a renderer when only the style changes: the grid keeps drawing and formatting the value itself (cellsformat still applies).
// Due: a class on the cell, from the row's data: overdue tasks that are not done.
const dueColumn = {
text: 'Due', datafield: 'due', width: 110, cellsformat: 'yyyy-MM-dd',
cellclassname: (row, field, value, rowdata) =>
rowdata.status !== 'Done' && value < new Date(new Date().toDateString()) ? 'overdue' : ''
};
A column with columntype: 'template' holds elements you create. createwidget creates them, once for each row element the grid shows, and receives the cell's element. The grid reuses its row elements when the rows it shows change (for example after a row is removed) and calls initwidget to point them at their new row. The button keeps the task's id in a data-id attribute for that reason, and reads it when it is clicked:
// A real button in the cell. createwidget runs once per row element; the grid reuses
// those elements when rows move, and initwidget points them at their new row.
const openColumn = {
text: '', datafield: 'id', width: 90, columntype: 'template',
createwidget: (row, column, value, cellElement) => {
const button = document.createElement('button');
button.type = 'button';
button.className = 'open-task';
button.textContent = 'Open';
button.dataset.id = String(value);
button.addEventListener('click', () => openTask(Number(button.dataset.id)));
cellElement.appendChild(button);
},
initwidget: (row, column, value, cellElement) => {
const button = cellElement.querySelector('button');
if (button) {
button.dataset.id = String(value);
}
}
};
The button is an ordinary element, so its click handler is an ordinary addEventListener. openTask writes the task under the grid with textContent. The columns go into the grid like any other column object:
$('#grid').jqxGrid({
theme: 'fluent',
width: '100%',
autoheight: true,
rowsheight: 40,
source,
columns: [
{ text: 'Task', datafield: 'title', width: 260, cellsrenderer: textCell },
{ text: 'Owner', datafield: 'owner', width: 100, cellsrenderer: textCell },
statusColumn,
progressColumn,
dueColumn,
openColumn
]
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Tasks</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="tasks.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/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>Tasks</h1>
<div id="grid"></div>
<p id="opened" aria-live="polite">Open a task to see it here.</p>
</main>
<script type="module">
const tasks = [
{ id: 1, title: 'Design the onboarding flow', owner: 'Nancy', status: 'Done', progress: 100, due: new Date(2026, 8, 12) },
{ id: 2, title: 'Migrate billing to the new API', owner: 'Andrew', status: 'In progress', progress: 65, due: new Date(2026, 9, 3) },
{ id: 3, title: 'Fix <script> injection in comments', owner: 'Janet', status: 'Blocked', progress: 20, due: new Date(2026, 9, 1) },
{ id: 4, title: 'Write the release notes', owner: 'Margaret', status: 'Open', progress: 0, due: new Date(2026, 9, 20) },
{ id: 5, title: 'Load-test the search service', owner: 'Steven', status: 'In progress', progress: 40, due: new Date(2026, 9, 9) },
{ id: 6, title: 'Accessibility audit', owner: 'Michael', status: 'Open', progress: 10, due: new Date(2026, 10, 2) }
];
// Cell renderers return HTML. Text that users typed goes through escapeHtml first:
// the third task's title would otherwise be markup.
function escapeHtml(text) {
return String(text).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
}
// A cell that shows its value as text. The grid writes values into the page as HTML,
// in columns without a renderer too, so every column of user text gets this renderer.
const textCell = (row, field, value) => `<div class="text-cell">${escapeHtml(value)}</div>`;
const statusClass = {
Open: 'status-open',
'In progress': 'status-progress',
Blocked: 'status-blocked',
Done: 'status-done'
};
const source = new $.jqx.dataAdapter({
localdata: tasks,
datatype: 'array',
id: 'id',
datafields: [
{ name: 'id', type: 'number' },
{ name: 'title', type: 'string' },
{ name: 'owner', type: 'string' },
{ name: 'status', type: 'string' },
{ name: 'progress', type: 'number' },
{ name: 'due', type: 'date' }
]
});
function openTask(id) {
const task = tasks.find((t) => t.id === id);
// textContent: the title is shown as text.
document.getElementById('opened').textContent = `Opened "${task.title}" (${task.owner})`;
}
// Status: a badge, coloured by a class for each status.
const statusColumn = {
text: 'Status', datafield: 'status', width: 120,
cellsrenderer: (row, field, value) => `<span class="status ${statusClass[value] ?? ''}">${escapeHtml(value)}</span>`
};
// Progress: a bar. The value goes through Number, so only a number reaches the HTML.
const progressColumn = {
text: 'Progress', datafield: 'progress', width: 150,
cellsrenderer: (row, field, value) => {
const percent = Number(value);
return `<div class="progress" role="progressbar" aria-valuenow="${percent}" aria-valuemin="0" aria-valuemax="100"><div style="width: ${percent}%"></div><span>${percent}%</span></div>`;
}
};
// Due: a class on the cell, from the row's data: overdue tasks that are not done.
const dueColumn = {
text: 'Due', datafield: 'due', width: 110, cellsformat: 'yyyy-MM-dd',
cellclassname: (row, field, value, rowdata) =>
rowdata.status !== 'Done' && value < new Date(new Date().toDateString()) ? 'overdue' : ''
};
// A real button in the cell. createwidget runs once per row element; the grid reuses
// those elements when rows move, and initwidget points them at their new row.
const openColumn = {
text: '', datafield: 'id', width: 90, columntype: 'template',
createwidget: (row, column, value, cellElement) => {
const button = document.createElement('button');
button.type = 'button';
button.className = 'open-task';
button.textContent = 'Open';
button.dataset.id = String(value);
button.addEventListener('click', () => openTask(Number(button.dataset.id)));
cellElement.appendChild(button);
},
initwidget: (row, column, value, cellElement) => {
const button = cellElement.querySelector('button');
if (button) {
button.dataset.id = String(value);
}
}
};
$('#grid').jqxGrid({
theme: 'fluent',
width: '100%',
autoheight: true,
rowsheight: 40,
source,
columns: [
{ text: 'Task', datafield: 'title', width: 260, cellsrenderer: textCell },
{ text: 'Owner', datafield: 'owner', width: 100, cellsrenderer: textCell },
statusColumn,
progressColumn,
dueColumn,
openColumn
]
});
</script>
</body>
</html>
The grid shows a badge for each status, a progress bar, and the due dates of late tasks in red. The third task's title reads Fix <script> injection in comments. Open on a row writes that task under the grid.