demo D194
Variation along an ordering in htmx
Volatility, growth and drawdown, from rows loaded out of order
grid.statistics.series(col, { by })
This grid computes volatility, growth and drawdown along an ordering, even from rows loaded out of order. It reads a series' behaviour over its own sequence, so trend and swings surface without the data arriving pre-sorted.
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.108.0/lattice-grid.min.css">
<!-- 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="variation-over-time-table" data-lattice-grid>
<thead>
<tr>
<th data-field="date">Date</th>
<th data-field="price">Price</th>
</tr>
</thead>
<tbody>
<tr data-id="36"><td>2026-02-06</td><td>98.25</td></tr>
<tr data-id="72"><td>2026-03-14</td><td>99.76</td></tr>
<tr data-id="108"><td>2026-04-19</td><td>101.87</td></tr>
<!-- the rest of the rows, rendered by your server -->
</tbody>
</table>
<pre id="out" style="margin-top: 12px"></pre>
<script type="module">
import { hydrateTable } from 'https://cdn.latticegrid.dev/lattice-grid@1.108.0/modules/htmx.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('variation-over-time-table'), {
toolPanel: { side: 'left', panels: ['filters', 'columns'] },
columns: [
{ field: 'date', title: 'Date', type: 'date', layout: { pin: 'start', width: 150 } },
{ field: 'price', title: 'Price', type: 'number' },
],
});
const out = document.getElementById('out');
const report = () => {
// by is required: reductions see rows as loaded, not in the grid's sort.
out.textContent = JSON.stringify(
grid.statistics.series('price', { by: 'date', periodsPerYear: 252 }), null, 2);
};
grid.on('filter:changed', report); // every figure follows the filters
report();
</script>