demo D187
Marking a baseline in htmx
"Mark all" resets every delta to now
grid.statistics.rebase(col)
This grid resets every delta to now with a single 'mark all', setting a fresh baseline. It lets a reader say 'watch from here', so change tracking restarts from the current moment rather than page load.
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">
<button id="mark">Mark all</button>
<!-- 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="shadow-rebase-table" data-lattice-grid>
<thead>
<tr>
<th data-field="symbol">Symbol</th>
<th data-field="price">Price</th>
</tr>
</thead>
<tbody>
<tr data-id="INS-0000000"><td>ELMW.G0</td><td>462.0258</td></tr>
<tr data-id="INS-0000001"><td>RVNS.A1</td><td>241.8711</td></tr>
<tr data-id="INS-0000002"><td>NRTH.E2</td><td>98.9614</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.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('shadow-rebase-table'), {
columns: [
{ field: 'symbol', title: 'Symbol', layout: { pin: 'start', width: 120 } },
{ field: 'price', title: 'Price', type: 'number' },
{ id: 'delta', title: 'Change', shadow: { of: 'price', kind: 'delta' }, type: 'number', format: { signed: true } },
{ id: 'first', title: 'Baseline', shadow: { of: 'price', kind: 'firstValue' }, type: 'number' },
],
});
// rebase moves every baseline to the current value, so the deltas start again.
document.getElementById('mark').onclick = () => grid.statistics.rebase('price');
</script>