Lattice Grid Buy a licence

demo D185

Shadow columns: rank and movement in htmx

Rank, percentile and places moved; sort by places moved for live top movers

shadow: { of, kind: 'rankChange' }

This grid adds shadow columns for rank, percentile and places moved, so sorting by places moved surfaces the live top movers. It turns a changing feed into a leaderboard of who rose and fell most, from the movements it already tracks.

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.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-rank-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-rank-table'), {
    highlightOnChange: { duration: 500 },
    columns: [
      { field: 'symbol', title: 'Symbol', layout: { pin: 'start', width: 120 } },
      { field: 'price', title: 'Price', type: 'number' },
      { id: 'rank',  title: 'Rank',   shadow: { of: 'price', kind: 'rank' }, type: 'number' },
      // rankChange is places climbed since the baseline: the top-movers column.
      { id: 'moved', title: 'Places moved', shadow: { of: 'price', kind: 'rankChange' }, type: 'number', format: { signed: true } },
      { id: 'pct',   title: 'Percentile',   shadow: { of: 'price', kind: 'percentile' }, type: 'number' },
    ],
    // Land sorted on the movers.
    state: { sort: [{ col: 'moved', dir: 'desc' }] },
  });
</script>