demo D186
Shadow columns: rate and streak in htmx
Speed of change, direction runs, and a sparkline of recent history
shadow: { of, kind: 'rate' }
This grid adds shadow columns for speed of change, runs in one direction, and a sparkline of recent history. It shows not just where a value is but how fast and which way it is moving, per row.
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="shadow-columns-rate-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-columns-rate-table'), {
highlightOnChange: { duration: 500 },
columns: [
{ field: 'symbol', title: 'Symbol', layout: { pin: 'start', width: 120 } },
{ field: 'price', title: 'Price', type: 'number' },
{ id: 'rate', title: 'Per second', shadow: { of: 'price', kind: 'rate' }, type: 'number', format: { signed: true } },
{ id: 'since', title: 'Since move', shadow: { of: 'price', kind: 'sinceUpdate' }, type: 'duration' },
{ id: 'hist', title: 'Recent', shadow: { of: 'price', kind: 'history' }, cell: { render: 'line' } },
],
});
</script>