demo D188
Rules that describe the data in htmx
The outliers, found in the data, beside a threshold you typed
when: { op: 'outlier' }
This grid highlights the outliers found in the data itself, shown beside a fixed threshold you typed, so you can compare the two. It lets a rule describe the shape of the data rather than a hard-coded cutoff, so unusual values surface even when you did not know the number in advance.
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="rules-from-the-data-table" data-lattice-grid>
<thead>
<tr>
<th data-field="circuit">Circuit</th>
<th data-field="region">Region</th>
<th data-field="charge">Charge · gt 3000</th>
</tr>
</thead>
<tbody>
<tr data-id="521"><td>LN-1521</td><td>North</td><td>2050</td></tr>
<tr data-id="1"><td>LN-1001</td><td>North</td><td>900</td></tr>
<tr data-id="2"><td>LN-1002</td><td>South</td><td>961.43</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('rules-from-the-data-table'), {
columnDefaults: { filter: true },
// Two columns of the same field: a threshold you type, and a rule that
// finds the outliers in the data itself.
formatting: {
charge: [{ when: { op: 'gt', value: 3000 }, style: { background: '#fff4e5' } }],
'charge-outlier': [{ when: { op: 'outlier' }, style: { background: '#fbeceb' } }],
},
columns: [
{ field: 'circuit', title: 'Circuit', layout: { pin: 'start', width: 180 } },
{ field: 'region', title: 'Region', filter: { type: 'set' } },
{ field: 'charge', title: 'Charge · gt 3000', type: 'number' },
{ field: 'charge', id: 'charge-outlier', title: 'Charge · outlier', type: 'number' },
],
});
</script>