Lattice Grid Buy a licence

demo D173

Brushing a time range in htmx

Drag a range on the chart and the grid narrows to it

brush: true

This lets you drag a range across a time chart and narrows the grid to it. It gives a reader a quick way to focus on a period, selecting the window on the chart and reading the matching rows in the grid.

Building…
Loading a live grid…

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: 300px"></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-time-brush-table" data-lattice-grid>
  <thead>
    <tr>
      <th data-field="date">Date</th>
      <th data-field="price">Price</th>
      <th data-field="volume">Volume</th>
    </tr>
  </thead>
  <tbody>
    <tr data-id="1"><td>2026-01-02</td><td>100.7</td><td>1000</td></tr>
    <tr data-id="2"><td>2026-01-03</td><td>101.78</td><td>8573</td></tr>
    <tr data-id="3"><td>2026-01-04</td><td>103.06</td><td>9184</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-time-brush-table'), {
    columns: [
      { field: 'date', title: 'Date', type: 'dateString', layout: { pin: 'start', width: 150 } },
      { field: 'price', title: 'Price', type: 'number', format: { decimals: 2 } },
      { field: 'volume', title: 'Volume', type: 'number', format: { notation: 'compact' } },
    ],
  });

  // brush lets a reader drag a range across the chart to narrow the grid to
  // those days, so one gesture moves the chart and the table together.
  createChart({ grid, container: '#chart', type: 'line', x: 'date', y: 'price', brush: true });
</script>