Documentation
The task tree on the left of jqxGantt is a table, and like a table it can be sorted by its columns and filtered by their values. The timeline on the right follows it: its bars are always in the order of the tree's rows, and a task the filter hides loses its bar too. This page sorts and filters the tasks, by the user and from code, and then works with the tasks the user selects.
The examples are complete pages like the ones in Get started with jqxGantt, which explains the files they load, the tree's columns and how to set options and call methods. A column can show any field of a task, so the tasks here have an owner field of their own and an Owner column.
sortMode decides whether the user can sort the tree by clicking the column headers:
sortMode | What a click on a header does |
|---|---|
'none' | Nothing. The default. |
'one' | Sorts by that column. A click on another header sorts by the other column instead. |
'many' | Adds the column to the sorting. The first column sorted decides the order; the next one orders the rows the first leaves equal, and so on. |
Each click on a header moves its column from not sorted to ascending, to descending, and back to not sorted. The header shows an arrow for the order and, with 'many', a number for the column's place in the sorting. Projects are sorted with the other rows at their level, and each one keeps its own tasks under it, sorted the same way. This page sorts by any number of columns, and its buttons sort and clear from code:
<p>
<button type="button" id="sort">Sort by owner, then start</button>
<button type="button" id="clear">Clear sorting</button>
</p>
<div id="gantt"></div>
<p id="status"></p>
const gantt = new jqxGantt('#gantt', {
theme: 'fluent',
width: '100%',
height: 'auto',
view: 'quarter',
treeSize: '60%',
sortMode: 'many',
taskColumns: [
{ label: 'Task', value: 'label', size: '45%' },
{ label: 'Owner', value: 'owner', size: '22%' },
{ label: 'Start', value: 'dateStart', dateFormat: { year: 'numeric', month: 'short', day: 'numeric' } }
],
source: [
{
id: 'design', type: 'project', label: 'Design', owner: 'Maya', dateStart: '2026-03-02T00:00:00', dateEnd: '2026-04-03T00:00:00', expanded: true,
tasks: [
{ id: 'sketches', type: 'task', label: 'Sketches', owner: 'Maya', dateStart: '2026-03-16T00:00:00', dateEnd: '2026-04-03T00:00:00' },
{ id: 'survey', type: 'task', label: 'Customer survey', owner: 'Liam', dateStart: '2026-03-09T00:00:00', dateEnd: '2026-03-27T00:00:00' },
{ id: 'brief', type: 'task', label: 'Write the brief', owner: 'Maya', dateStart: '2026-03-02T00:00:00', dateEnd: '2026-03-06T00:00:00' }
]
},
{
id: 'build', type: 'project', label: 'Build', owner: 'Liam', dateStart: '2026-04-06T00:00:00', dateEnd: '2026-05-15T00:00:00', expanded: true,
tasks: [
{ id: 'pilot', type: 'task', label: 'Pilot', owner: 'Omar', dateStart: '2026-05-04T00:00:00', dateEnd: '2026-05-15T00:00:00' },
{ id: 'prototype', type: 'task', label: 'Prototype', owner: 'Liam', dateStart: '2026-04-06T00:00:00', dateEnd: '2026-04-24T00:00:00' },
{ id: 'review', type: 'task', label: 'Design review', owner: 'Maya', dateStart: '2026-04-27T00:00:00', dateEnd: '2026-04-29T00:00:00' }
]
}
]
});
Sorting changes only the order of the rows. getTasks() still returns the tasks in the order of the source.
sort(columns) sorts by a list of columns, in order, and clearSort() goes back to the order of the source. Both work only when sortMode is 'one' or 'many'; with 'one', sort keeps only the last column of the list.
document.getElementById('sort').addEventListener('click', () => {
gantt.sort([
{ value: 'owner', sortOrder: 'asc', type: 'task' },
{ value: 'dateStart', sortOrder: 'asc', type: 'task' }
]);
});
document.getElementById('clear').addEventListener('click', () => {
gantt.clearSort();
});
| Field | Value |
|---|---|
value | The column's value, the task field it shows, such as 'owner' or 'dateStart' |
sortOrder | 'asc' or 'desc' |
type | 'task' for the task tree ('resource' sorts the resource tree of Resources) |
In 27.1.0 and earlier, sort() without an argument does not remove the sorting, as the API reference says it does: call clearSort(). A sort: 'asc' field in a column of taskColumns, which some older demos use, does nothing either. To open the chart sorted, call sort when the chart is ready, as the custom sort example below does.
The chart raises its events on its jqx-gantt-chart element. They are DOM events, so addEventListener receives them there, and they bubble up to #gantt as well. The page writes each new sorting into its status line:
// The chart's events are DOM events of its jqx-gantt-chart element.
const chart = document.querySelector('#gantt jqx-gantt-chart');
chart.addEventListener('sort', (event) => {
const { sortDataFields, sortOrders } = event.detail;
document.getElementById('status').textContent = sortDataFields.length
? 'Sorted by ' + sortDataFields.map((field, i) => `${field} (${sortOrders[i]})`).join(', ')
: 'Not sorted';
});
event.detail of the sort event holds:
| Field | Value |
|---|---|
sortDataFields | The sorted columns' values, in order, such as ['owner', 'dateStart']; empty when nothing is sorted |
sortOrders | Their orders, such as ['asc', 'asc'] |
sortDataTypes | Their data types, such as ['string', 'date'] |
columns | The sorted column objects; dataField is the column's value |
type | 'interaction' when the user sorted, 'programmatic' when sort or clearSort did |
A sort call with two columns raises the event twice in 27.1.0 and earlier: first for the first column alone, then for both. Read the last one.
Keep the year in a date column's dateFormat, as the Start column above does. Without it, 27.1.0 and earlier keep that column's dates in the year 2001, and sorts and filters them that way: a task that starts on December 15, 2025 sorts after one that starts in April 2026, and a filter for the dates from April 2026 hides every row.
A row whose task has no value for a column shows Unassigned in that column. That is why the projects here have an owner too.
The default sort orders text alphabetically, which puts the priorities High, Low, Medium in that order. sortFunction replaces the sort with your own. The chart calls it with four arguments:
| Argument | What it holds |
|---|---|
records | The rows of the tree, with the fields of their tasks. Sort them in place with records.sort. |
dataFields | The values of the columns to sort by |
orders | 'asc' or 'desc' for each of them |
compareFunctions | The default compare function of each of them, for the columns you do not sort yourself |
This page sorts the Priority column by rank and every other column the default way, and sorts by priority when it opens:
// Priorities in the order they matter, not in alphabetical order.
const rank = { High: 0, Medium: 1, Low: 2 };
function sortTasks(records, dataFields, orders, compareFunctions) {
records.sort((a, b) => {
for (let i = 0; i < dataFields.length; i++) {
const field = dataFields[i];
const result = field === 'priority'
? rank[a.priority] - rank[b.priority]
: compareFunctions[i](a[field], b[field]);
if (result !== 0) {
return orders[i] === 'desc' ? -result : result;
}
}
return 0;
});
}
const gantt = new jqxGantt('#gantt', {
theme: 'fluent',
width: '100%',
height: 'auto',
view: 'quarter',
treeSize: '45%',
sortMode: 'one',
sortFunction: sortTasks,
taskColumns: [
{ label: 'Task', value: 'label', size: '55%' },
{ label: 'Priority', value: 'priority' }
],
source: [
{ id: 'login', type: 'task', label: 'Fix the login error', priority: 'High', dateStart: '2026-03-02T00:00:00', dateEnd: '2026-03-06T00:00:00' },
{ id: 'icons', type: 'task', label: 'New icons', priority: 'Low', dateStart: '2026-03-09T00:00:00', dateEnd: '2026-03-20T00:00:00' },
{ id: 'export', type: 'task', label: 'CSV export', priority: 'Medium', dateStart: '2026-03-04T00:00:00', dateEnd: '2026-03-18T00:00:00' },
{ id: 'payments', type: 'task', label: 'Payment timeout', priority: 'High', dateStart: '2026-03-09T00:00:00', dateEnd: '2026-03-13T00:00:00' },
{ id: 'help', type: 'task', label: 'Help pages', priority: 'Low', dateStart: '2026-03-23T00:00:00', dateEnd: '2026-04-03T00:00:00' },
{ id: 'search', type: 'task', label: 'Faster search', priority: 'Medium', dateStart: '2026-03-16T00:00:00', dateEnd: '2026-04-10T00:00:00' }
]
});
// Sort by priority when the chart opens.
document.querySelector('#gantt jqx-gantt-chart').whenReady(() => {
gantt.sort([{ value: 'priority', sortOrder: 'asc', type: 'task' }]);
});
A click on Priority then puts the low priorities first. A click on Task sorts the tasks alphabetically, through compareFunctions.
taskFiltering: true adds a Filter box above the column headers. Whatever the user types there is looked for in every text column, ignoring case: maya keeps the tasks whose name or owner contains it. Dates are not searched. The tree keeps the project of each task that passes, so the task still shows where it belongs, and the timeline shows only the rows that are left. getTasks() still returns every task.
addFilter(column, filterGroup) filters one column. The first argument names the column, as in sort. The second is a FilterGroup, which the chart's script provides as JQX.Utilities.FilterGroup: its createFilter(type, value, condition) makes a condition, and its addFilter(operator, filter) adds it to the group. These buttons filter the owner and the task name:
<p>
<button type="button" id="maya">Maya's tasks</button>
<button type="button" id="reviews">Reviews</button>
<button type="button" id="clear">Clear filters</button>
</p>
<div id="gantt"></div>
<p id="status"></p>
// A filter is a FilterGroup: one or more conditions on one column.
function filterColumn(column, value, condition) {
const group = new JQX.Utilities.FilterGroup();
group.addFilter('or', group.createFilter('string', value, condition));
gantt.addFilter({ type: 'task', value: column }, group);
}
document.getElementById('maya').addEventListener('click', () => {
filterColumn('owner', 'Maya', 'EQUAL');
});
document.getElementById('reviews').addEventListener('click', () => {
filterColumn('label', 'review', 'CONTAINS');
});
document.getElementById('clear').addEventListener('click', () => {
gantt.clearFilters();
});
// filters: one [column, FilterGroup] pair for each filtered column (none when the filters are removed).
const chart = document.querySelector('#gantt jqx-gantt-chart');
chart.addEventListener('filter', (event) => {
const parts = (event.detail.filters || []).map(([column, group]) =>
group.filters.map((filter) => `${column} ${filter.condition} "${filter.value}"`).join(' or '));
document.getElementById('status').textContent = parts.length ? 'Filter: ' + parts.join(' / ') : 'No filter';
});
The rules, as version 27.1.0 applies them:
type is 'string', 'numeric', 'date' or 'boolean'. The string conditions include 'CONTAINS', 'EQUAL', 'STARTS_WITH', 'ENDS_WITH', 'DOES_NOT_CONTAIN' and 'NOT_EQUAL', each also as _CASE_SENSITIVE; the others take 'EQUAL', 'LESS_THAN', 'GREATER_THAN_OR_EQUAL' and the like.'or' pass a task when any of them does: two 'EQUAL' conditions for Omar and Liam keep both owners' tasks.FilterGroup. A plain object with the same fields filters nothing.clearFilters() removes every filter.addFilter also writes the filter's value into the Filter box. For a date filter, such as createFilter('date', new Date(2026, 3, 1), 'GREATER_THAN_OR_EQUAL') on dateStart, that write fails in 27.1.0 and earlier: the rows are filtered, and then addFilter throws Invalid 'value' property value type!. With the filter row there is no box, and a date filter works without the error.
The filter event follows every change, made by the user or from code. Its event.detail holds type ('task'), action ('add', or 'remove' when the last filter goes) and filters: one [column, filterGroup] pair for each filtered column, absent after a 'remove'. Each condition of a group is in its filters array, with its value, condition and type ('stringFilter'). Text typed into the Filter box arrives as one 'CONTAINS' filter for each text column.
filterRow: true, together with taskFiltering, replaces the Filter box with a row under the headers: a box for a value under each column, and next to it the condition, contains at first. A click on the condition lists the others, such as equal and starts with. A date column gets a date field.
In 27.1.0 and earlier, jqx.gantt.css has no styles for this row, and each condition is squeezed to a few pixels. The example page gives it room with one rule in its stylesheet:
/* jqx.gantt.css has no styles for the filter row (27.1.0 and earlier), which leaves each
condition box a few pixels wide. */
#gantt .jqx-table-filter-row td > div {
grid-template-columns: minmax(0, 1fr) 6em;
gap: 4px;
}
Here is the whole page. It also has the column menu and column resizing, described next:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jqxGantt: filter row, column menu and column resizing</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/gantt/jqx.gantt.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/jqxgantt.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgantt.api.js"></script>
<style>
/* jqx.gantt.css has no styles for the filter row (27.1.0 and earlier), which leaves each
condition box a few pixels wide. */
#gantt .jqx-table-filter-row td > div {
grid-template-columns: minmax(0, 1fr) 6em;
gap: 4px;
}
/* The column menu is added to the end of the page and takes the page's text
colour: give it the theme's. */
.jqx-table-column-menu {
color: var(--jqx-surface-color);
}
</style>
</head>
<body>
<div id="gantt"></div>
<p id="status"></p>
<script type="module">
const gantt = new jqxGantt('#gantt', {
theme: 'fluent',
width: '100%',
height: 'auto',
view: 'quarter',
treeSize: '60%',
sortMode: 'one',
taskFiltering: true,
filterRow: true,
columnResize: true,
columnResizeFeedback: true,
columnMinWidth: 80,
taskColumns: [
{ label: 'Task', value: 'label', size: '55%' },
{ label: 'Owner', value: 'owner' }
],
source: [
{
id: 'design', type: 'project', label: 'Design', owner: 'Maya', dateStart: '2026-03-02T00:00:00', dateEnd: '2026-04-03T00:00:00', expanded: true,
tasks: [
{ id: 'brief', type: 'task', label: 'Write the brief', owner: 'Maya', dateStart: '2026-03-02T00:00:00', dateEnd: '2026-03-06T00:00:00' },
{ id: 'survey', type: 'task', label: 'Customer survey', owner: 'Liam', dateStart: '2026-03-09T00:00:00', dateEnd: '2026-03-27T00:00:00' },
{ id: 'sketches', type: 'task', label: 'Sketches', owner: 'Maya', dateStart: '2026-03-16T00:00:00', dateEnd: '2026-04-03T00:00:00' }
]
},
{
id: 'build', type: 'project', label: 'Build', owner: 'Liam', dateStart: '2026-04-06T00:00:00', dateEnd: '2026-05-15T00:00:00', expanded: true,
tasks: [
{ id: 'prototype', type: 'task', label: 'Prototype', owner: 'Liam', dateStart: '2026-04-06T00:00:00', dateEnd: '2026-04-24T00:00:00' },
{ id: 'review', type: 'task', label: 'Design review', owner: 'Maya', dateStart: '2026-04-27T00:00:00', dateEnd: '2026-04-29T00:00:00' },
{ id: 'pilot', type: 'task', label: 'Pilot', owner: 'Omar', dateStart: '2026-05-04T00:00:00', dateEnd: '2026-05-15T00:00:00' }
]
}
]
});
const chart = document.querySelector('#gantt jqx-gantt-chart');
// columnMenu set in the options does not reach the tree (27.1.0 and earlier): turn it on when the chart is ready.
chart.whenReady(() => {
gantt.columnMenu = true;
});
chart.addEventListener('columnResize', (event) => {
const { dataField, width } = event.detail;
document.getElementById('status').textContent = `${dataField} is now ${Math.round(width)} px wide`;
});
</script>
</body>
</html>
columnMenu: true adds a button to each column header. It shows when the pointer is over the header and opens a menu: Sort Ascending, Sort Descending, Remove Sort once the column is sorted, Columns and Reset. Columns lists the other columns, each with a check box that hides or shows it; the first column, which holds the tree, cannot be hidden. Reset undoes what the menu changed. The sort entries need sortMode, and raise the sort event like a click on the header.
Three things to know in 27.1.0 and earlier:
columnMenu: true in the options is not passed on to the tree. Set the option when the chart is ready, as the page does with chart.whenReady.taskFiltering on and no filter row, the column menu hides the Filter box but the timeline keeps room for it, so every row of the tree sits one row above its bar. Use the column menu with filterRow, as the page does, or without filtering.With columnResize: true, the user can drag the right edge of a column header to change the column's width. columnResizeFeedback: true draws a line and the new width in pixels while the edge moves, and columnMinWidth (50 pixels by default) is the narrowest a column can get: the page sets 80. When the user lets go, the columnResize event gives the column's dataField, its new width in pixels and widthInPercentages, and its headerCellElement. The page writes the width into its status line:
chart.addEventListener('columnResize', (event) => {
const { dataField, width } = event.detail;
document.getElementById('status').textContent = `${dataField} is now ${Math.round(width)} px wide`;
});
A click on a row of the tree, or on a bar of the timeline, selects the task; a second click unselects it. Each click adds to the selection, so the user selects several tasks without holding a key. The selected rows and bars are highlighted, and a selected bar shows its handles. showSelectionColumn: true adds a check box to each row and one to the header, which selects all the tasks.
<p>
<button type="button" id="select">Select the reviews</button>
<button type="button" id="later">Move a week later</button>
<button type="button" id="clear">Clear selection</button>
</p>
<div id="gantt"></div>
<p id="status"></p>
<p id="clicked"></p>
const shortDate = { month: 'short', day: 'numeric' };
const gantt = new jqxGantt('#gantt', {
theme: 'fluent',
width: '100%',
height: 'auto',
view: 'quarter',
treeSize: '45%',
showSelectionColumn: true,
keyboardNavigation: true,
taskColumns: [
{ label: 'Task', value: 'label', size: '50%' },
{ label: 'Start', value: 'dateStart', dateFormat: shortDate },
{ label: 'End', value: 'dateEnd', dateFormat: shortDate }
],
source: [
{ id: 'brief', type: 'task', label: 'Write the brief', dateStart: '2026-03-02T00:00:00', dateEnd: '2026-03-06T00:00:00' },
{ id: 'brief-review', type: 'task', label: 'Brief review', dateStart: '2026-03-09T00:00:00', dateEnd: '2026-03-10T00:00:00' },
{ id: 'sketches', type: 'task', label: 'Sketches', dateStart: '2026-03-11T00:00:00', dateEnd: '2026-03-20T00:00:00' },
{ id: 'design-review', type: 'task', label: 'Design review', dateStart: '2026-03-23T00:00:00', dateEnd: '2026-03-24T00:00:00' },
{ id: 'prototype', type: 'task', label: 'Prototype', dateStart: '2026-03-25T00:00:00', dateEnd: '2026-04-10T00:00:00' }
]
});
The selectedTaskIds option lists the tasks to select, but 27.1.0 and earlier ignore it when the chart is created. Set it when the chart is ready:
const chart = document.querySelector('#gantt jqx-gantt-chart');
const status = document.getElementById('status');
// The selectedTaskIds option is not applied when the chart is created (27.1.0 and earlier),
// so set the first selection when the chart is ready.
chart.whenReady(() => {
gantt.selectedTaskIds = ['sketches'];
});
// change: the selected tasks changed (by a click, a key or a method).
chart.addEventListener('change', (event) => {
if (event.target !== chart) {
return;
}
const tasks = gantt.getSelectedTasks();
status.textContent = tasks.length
? 'Selected: ' + tasks.map((task) => task.label).join(', ')
: 'No tasks selected';
});
The methods for the selection:
| Method | What it does |
|---|---|
selectTask(id) | Adds a task to the selection |
unselectTask(id) | Removes a task from it |
getSelectedIds() | Returns { task: [...], resources: [...] } with the selected ids, or null when nothing is selected |
getSelectedTasks() | Returns the selected task objects in the order of the rows, or an empty array |
clearSelection() | Unselects everything; see below |
Read the selection with these methods. The widget's own selectedTaskIds property keeps the value you last set, whatever the user selects since.
The change event follows every change of the selection, by a click, a key or a method. Its event.detail holds type ('task'), value, the selected ids, and oldValue, the ids before. A change event of an input inside the chart, such as the filter box or the task editor, bubbles through the same element, so the page checks that the chart itself raised it (event.target === chart).
The itemClick event follows a click on a row or a bar. Its event.detail holds the task's id, the task as item, type and the originalEvent. In 27.1.0 and earlier, type is 'task' for a project too (the API reference says 'project'); check item.type instead.
// itemClick: a row of the tree or a bar of the timeline was clicked.
chart.addEventListener('itemClick', (event) => {
const { id, type, item } = event.detail;
document.getElementById('clicked').textContent = `Clicked the ${type} "${item.label}" (id ${id})`;
});
document.getElementById('select').addEventListener('click', () => {
gantt.selectTask('brief-review');
gantt.selectTask('design-review');
});
Move a week later moves every selected task seven days with updateTask. The tasks stay selected, so a second click moves them again:
// Act on the selected tasks: move each one a week later.
function weekLater(date) {
const result = new Date(date);
result.setDate(result.getDate() + 7);
return result;
}
document.getElementById('later').addEventListener('click', () => {
for (const task of gantt.getSelectedTasks()) {
gantt.updateTask(task.id, {
dateStart: weekLater(task.dateStart),
dateEnd: weekLater(task.dateEnd)
});
}
});
The function adds days with setDate rather than adding seven times 24 hours, which would leave a task an hour off its day when the week crosses a change to or from summer time.
In 27.1.0 and earlier, clearSelection() throws Cannot read properties of undefined (reading 'querySelectorAll') in a chart without resources, after it has unselected the tasks. Unselect the tasks one by one instead:
// clearSelection() throws in a chart without resources (27.1.0 and earlier):
// unselect the tasks one by one instead.
document.getElementById('clear').addEventListener('click', () => {
const selected = gantt.getSelectedIds();
if (selected) {
selected.task.forEach((id) => gantt.unselectTask(id));
}
});
disableSelection: true turns selection off: clicks on rows and bars select nothing, the check box column is gone, and getSelectedIds() returns null. In 27.1.0 and earlier, selectTask then throws a TypeError instead of doing nothing, so do not call it.
With keyboardNavigation: true, a click on a cell of the tree puts the focus there, and these keys work:
| Key | What it does |
|---|---|
| Arrow keys | Move the focus to the next cell |
| Space | Selects the focused task, or unselects it |
| Enter | Opens the task editor for the focused task; Escape closes it |
| Delete | Asks to confirm deleting the focused task |
Without it, the keys do nothing in the tree. The selection page above has it on.