Documentation
jqxGantt can save the plan as an Excel, CSV, TSV, HTML, JSON, XML or PDF file, and print it. Both work on the task tree, the table on the left: the file and the printed page hold its columns and rows, not the timeline with its bars and connections.
This page exports a plan to each format, shows which scripts each format needs and what the files contain, names the files, gets the content without a download, prints the tree, and prints the timeline with the browser. It builds on the getting-started guide, which shows how to load the files, describe tasks and choose the tree's columns. Each example is a complete page.
exportData(format) saves the tree as a file in that format, which the browser downloads. Each button of this page exports the plan in one format; Print calls print(), described below:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jqxGantt: export and print the task tree</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>
<!-- Export: JSZip for every format, pdfmake and its fonts for PDF -->
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/scripts/jszip.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/scripts/pdfmake.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/scripts/vfs_fonts.js"></script>
<style>
/* Narrower months (70px by default), so that the plan fits beside the tree */
#gantt {
--jqx-gantt-chart-timeline-cell-min-size: 45px;
}
</style>
</head>
<body>
<div id="plan">
<p>
<button type="button" data-format="xlsx">Excel</button>
<button type="button" data-format="csv">CSV</button>
<button type="button" data-format="tsv">TSV</button>
<button type="button" data-format="html">HTML</button>
<button type="button" data-format="json">JSON</button>
<button type="button" data-format="xml">XML</button>
<button type="button" data-format="pdf">PDF</button>
<button type="button" id="print">Print</button>
</p>
<div id="gantt"></div>
</div>
<script type="module">
const shortDate = { year: 'numeric', month: 'short', day: 'numeric' };
const gantt = new jqxGantt('#gantt', {
theme: 'fluent',
width: '100%',
height: 'auto',
view: 'quarter',
treeSize: '58%',
taskColumns: [
{ label: 'Task', value: 'label', size: '36%' },
{ label: 'Start', value: 'dateStart', dateFormat: shortDate },
{ label: 'End', value: 'dateEnd', dateFormat: shortDate },
{ label: 'Done', value: 'progress', size: '12%', formatFunction: (progress) => `${progress}%` }
],
source: [
{
id: 'relaunch',
type: 'project',
label: 'Website relaunch',
dateStart: '2026-01-05T00:00:00',
dateEnd: '2026-06-26T00:00:00',
expanded: true,
tasks: [
{
id: 'research', type: 'task', label: 'Research', dateStart: '2026-01-05T00:00:00', dateEnd: '2026-02-27T00:00:00', progress: 100,
connections: [{ target: 'design', type: 1 }]
},
{
id: 'design', type: 'task', label: 'Design', dateStart: '2026-03-02T00:00:00', dateEnd: '2026-04-24T00:00:00', progress: 60,
connections: [{ target: 'signoff', type: 1 }]
},
{
id: 'signoff', type: 'milestone', label: 'Sign-off', dateStart: '2026-04-24T00:00:00',
connections: [{ target: 'build', type: 1 }]
},
{ id: 'build', type: 'task', label: 'Build', dateStart: '2026-04-27T00:00:00', dateEnd: '2026-06-26T00:00:00' }
]
},
{ id: 'content', type: 'task', label: 'Content migration', dateStart: '2026-04-06T00:00:00', dateEnd: '2026-06-26T00:00:00', progress: 25 }
]
});
// The name of the exported files. In 27.1.0 and earlier the dataExportFileName option
// does not reach the chart, so set the name on the chart element.
const chart = document.querySelector('#gantt jqx-gantt-chart');
chart.dataExport.fileName = 'website-relaunch';
// Each button exports the task tree in its format; Print prints it.
for (const button of document.querySelectorAll('[data-format]')) {
button.addEventListener('click', () => gantt.exportData(button.dataset.format));
}
document.getElementById('print').addEventListener('click', () => gantt.print());
</script>
</body>
</html>
The style rule makes the months of the timeline narrower than their default 70 pixels, so that the plan fits beside a tree of four columns. The timeline page describes the timeline's settings.
The formats, and the file each one gives:
| Button | exportData | The file |
|---|---|---|
| Excel | 'xlsx' | A workbook with one sheet. A project's tasks are an outline group, which Excel can collapse. |
| CSV | 'csv' | Text, every value in double quotes, separated by a comma and a space. It starts with a byte order mark, so Excel reads it as UTF-8. |
| TSV | 'tsv' | The same rows, separated by tabs. |
| HTML | 'html' | A web page with a table. A project's - sign hides its tasks. |
| JSON | 'json' | An array: first the column labels, then one object per top-level row, with a project's tasks in its rows array. |
| XML | 'xml' | A table of row elements, nested like the JSON. |
'pdf' | A table on portrait pages, the tasks indented under their project. |
exportData('png') also works, with one more script (see the next section): it saves a picture of the same table, not of the chart.
Export needs scripts that jqxgantt.api.js does not contain. They are in the package's scripts/ folder, next to jqwidgets/:
<!-- Export: JSZip for every format, pdfmake and its fonts for PDF -->
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/scripts/jszip.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/scripts/pdfmake.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/scripts/vfs_fonts.js"></script>
| Script | Needed for | Without it |
|---|---|---|
jszip.min.js | Every format, CSV and JSON included | exportData throws jqx-gantt-chart: Missing reference to jszip.min.js in method exportData., logs the same text in the console, and saves nothing. |
pdfmake.min.js | exportData('pdf') throws jqx-gantt-chart: Missing reference to pdfMake.min.js in method exportData. (with vfs_fonts.js on the page: pdfMake.createPdf is not a function). The other formats work. | |
vfs_fonts.js | PDF: the fonts | No PDF is saved; the page reports File 'Roboto-Medium.ttf' not found in virtual file system. Load it after pdfmake.min.js: loaded before, it has the same effect. |
html2canvas.min.js | PNG | exportData('png') throws Missing reference to 'html2canvas.min.js'. |
The check for JSZip comes first, for every format: a page that exports only CSV still needs jszip.min.js. With npm, the same files are in node_modules/jqwidgets-scripts/scripts/.
A file holds the columns of the tree that are visible, with their labels as the header row, and one row for each project, task and milestone, in the order of the tree. The page below shows the plan as CSV text:
formatFunction is not used: the Done column shows 60% in the tree and 60 in the file.locale set to 'en-GB', the same date is 2 March 2026 at 00:00.id, type and connections. To export a field, add a column for it to taskColumns.dataExport.exportFiltered to true on the jqx-gantt-chart element. The sorting and filtering page describes filters.In 27.1.0 and earlier the export reads each date back from the text in its cell, so the file can only be as exact as that text. Give date columns a dateFormat with the year and the month as a word, as the page does with { year: 'numeric', month: 'short', day: 'numeric' }. Without the year ({ month: 'short', day: 'numeric' }), every exported date falls in 2001. A day-first numeric date, such as 02/03/2026 for March 2 under 'en-GB', comes out as February 3.
The files are called jqxGanttChart, with the extension of the format. The dataExportFileName option is meant to change that, but in 27.1.0 and earlier the widget does not pass it on to the chart: given to new jqxGantt or set later, the files keep the name jqxGanttChart. Set the name on the jqx-gantt-chart element instead, as the page does:
// The name of the exported files. In 27.1.0 and earlier the dataExportFileName option
// does not reach the chart, so set the name on the chart element.
const chart = document.querySelector('#gantt jqx-gantt-chart');
chart.dataExport.fileName = 'website-relaunch';
The chart adds the extension unless the name already ends with it: with the name 'plan.csv', a CSV file is plan.csv and an Excel file plan.csv.xlsx. The name is also the title of the window that print() opens.
When the file name is null, exportData does not download a file: it returns the content, or passes it to a callback, the second argument. Use it to show the content, or to send it to your server. This page shows the CSV text of the plan, and uploads the Excel file:
<p>
<button type="button" id="showCsv">Show as CSV</button>
<button type="button" id="upload">Upload as Excel</button>
<span id="status"></span>
</p>
<div id="gantt"></div>
<pre id="csv" hidden></pre>
const chart = document.querySelector('#gantt jqx-gantt-chart');
const status = document.getElementById('status');
// Without a file name, exportData returns the content (or passes it
// to the callback) instead of downloading a file.
function exportContent(format, callback) {
const fileName = chart.dataExport.fileName;
chart.dataExport.fileName = null;
try {
return gantt.exportData(format, callback);
} finally {
chart.dataExport.fileName = fileName;
}
}
document.getElementById('showCsv').addEventListener('click', () => {
const csv = document.getElementById('csv');
csv.textContent = exportContent('csv');
csv.hidden = false;
});
// The Excel file is built asynchronously: the callback gets it as a Blob.
document.getElementById('upload').addEventListener('click', () => {
exportContent('xlsx', async (blob) => {
const body = new FormData();
body.append('file', blob, 'website-relaunch.xlsx');
try {
const response = await fetch('/api/plan-exports', { method: 'POST', body });
status.textContent = response.ok ? `Uploaded ${blob.size} bytes.` : `Upload failed: ${response.status}`;
} catch (error) {
status.textContent = `Upload failed: ${error.message}`;
}
});
});
exportContent clears the name, exports, and puts the name back. /api/plan-exports stands for your server's address; the server receives the file as the form field file. What comes back for each format:
| Format | Without a file name |
|---|---|
'csv', 'tsv', 'html', 'json', 'xml' | Returns the text (CSV without the byte order mark), and passes it to the callback too. |
'xlsx' | Returns nothing. The file is built asynchronously; the callback gets it as a Blob. |
'pdf' | Returns a pdfmake document, with the methods getBlob(callback), open(), print() and download(). |
With a file name, the callback is not called. The API reference describes the callback as a way to format the exported data; in 27.1.0 and earlier it only receives the finished content.
print() opens a window of 800 by 500 pixels, writes the HTML export into it, opens the browser's print dialog for it, and closes the window. The window's title is the file name. What it prints is the HTML file of the first example: the tree as a table, without the timeline.
The table has the background and text colours of the chart's theme. With a dark theme it is light text on a dark background, and browsers leave out background colours when they print: on white paper the light text comes out pale (grey in Chrome).
To choose what the printed page looks like, write the window yourself. This page exports the HTML without a file name, adds a title, a heading and its own styles, and prints it black on white whatever the page's theme:
<p>
<button type="button" id="print">Print the plan</button>
<span id="status"></span>
</p>
<div id="gantt"></div>
const chart = document.querySelector('#gantt jqx-gantt-chart');
const status = document.getElementById('status');
// A title; a table as wide as the page, black on white whatever the page's theme,
// with grey borders; no expand/collapse signs (their space keeps the indent).
const printHead = `<title>Website relaunch plan</title>
<style>
body { margin: 0; font-family: Arial, Helvetica, sans-serif; }
h1 { margin: 0 0 12px; font-size: 20px; }
table { width: 100%; table-layout: auto !important; background-color: #fff !important; color: #000 !important; }
th, td { width: auto !important; border: 1px solid #c8c8c8 !important; text-align: left; }
.toggle-element { visibility: hidden; }
</style>`;
function printPlan() {
// Without a file name, exportData('html') returns the page as a string.
const fileName = chart.dataExport.fileName;
chart.dataExport.fileName = null;
const html = gantt.exportData('html');
chart.dataExport.fileName = fileName;
const printWindow = window.open('', '', 'width=800,height=600');
if (!printWindow) {
status.textContent = 'Allow pop-ups for this page to print the plan.';
return;
}
printWindow.document.write(html
.replace('</head>', `${printHead}</head>`)
.replace('<body>', '<body><h1>Website relaunch: plan</h1>'));
printWindow.document.close();
printWindow.print();
printWindow.close();
}
document.getElementById('print').addEventListener('click', printPlan);
The styles use !important because the export writes the table's colours and layout into its style attribute. window.open returns null when the browser blocks the window; the page then says so in its status line.
The bars and connections are printed by the browser, with the rest of the page: window.print(), or the browser's own Print command. Three things make the chart print well:
/* Browsers leave out background colours when they print; the bars are background colours. */
#gantt {
print-color-adjust: exact;
-webkit-print-color-adjust: exact;
}
@page {
size: landscape;
}
@media print {
.toolbar {
display: none;
}
}
// The chart is drawn for the width of the screen. Before the browser prints
// (from the button or its own Print command), draw it as wide as the paper.
window.addEventListener('beforeprint', () => {
gantt.width = 960;
});
window.addEventListener('afterprint', () => {
gantt.width = '100%';
});
document.getElementById('print').addEventListener('click', () => window.print());
print-color-adjust: exact keeps them; without it the bars print white.beforeprint and afterprint events also come with the browser's own Print command.@page { size: landscape; } asks for landscape paper, and the @media print rule leaves the button out.<p class="toolbar">
<button type="button" id="print">Print the chart</button>
</p>
<div id="gantt"></div>
An exported file is for people: a spreadsheet, a document, a page to print. The chart has no method that reads one back. To keep the plan for the chart itself, with ids, connections and exact dates, save getState() and load it with loadState(state), as the getting-started guide shows in Save and restore the plan.