demo D215
Gantt in htmx
A row label with a start and an end, coloured by phase
type: 'gantt', label, start, end
This draws a Gantt-style chart from a row label with a start and an end, coloured by phase. It lays activities out along a timeline so overlaps and sequence read at a glance, from ordinary rows with two dates.
This is the htmx version. A server-rendered table is upgraded in place, so the page is readable before any script runs and gains the full grid when the module loads, which suits a progressively enhanced app.
The configuration
<link rel="stylesheet" href="https://cdn.latticegrid.dev/lattice-grid@1.107.0/lattice-grid.min.css">
<div id="chart" style="height: 320px"></div>
<!-- A real, server-rendered table: readable with JavaScript off. data-field on
each header names the column that cell becomes, and data-id on each row is
the key the grid carries it under. -->
<table id="chart-types-gantt-table" data-lattice-grid>
<thead>
<tr>
<th data-field="task">Task</th>
<th data-field="phase">Phase</th>
<th data-field="start">Start</th>
<th data-field="end">End</th>
</tr>
</thead>
<tbody>
<tr data-id="1"><td>Discovery</td><td>Plan</td><td>2026-01-06</td><td>2026-01-14</td></tr>
<tr data-id="2"><td>Build</td><td>Deliver</td><td>2026-01-15</td><td>2026-02-20</td></tr>
<tr data-id="3"><td>Handover</td><td>Deliver</td><td>2026-02-23</td><td>2026-02-27</td></tr>
<!-- the rest of the rows, rendered by your server -->
</tbody>
</table>
<script type="module">
import { hydrateTable } from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/modules/htmx.esm.min.js';
import { createChart } from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/modules/charts.esm.min.js';
// The markup carries the rows; a server-rendered table's column types are
// declared in the config hydrateTable takes. The grid replaces the table
// where it stood.
const grid = hydrateTable(document.getElementById('chart-types-gantt-table'), {
columns: [
{ field: 'task', title: 'Task', layout: { width: 160 } },
{ field: 'phase', title: 'Phase', filter: { type: 'set' } },
{ field: 'start', title: 'Start', type: 'date' },
{ field: 'end', title: 'End', type: 'date' },
],
});
// Gantt reads a row label and a start and end date; series colours the bars.
createChart({ grid, container: '#chart', type: 'gantt',
label: 'task', start: 'start', end: 'end', series: 'phase', legend: true });
</script>