demo D185
Shadow columns: rank and movement in Svelte
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.
This is the Svelte version. A use action attaches the grid to a plain element, so no framework runtime is passed in and the component stays small, while the configuration is ordinary Svelte state.
The configuration
<script>
import { createGrid } from 'https://cdn.latticegrid.dev/lattice-grid@1.108.0/lattice-grid.esm.min.js';
import createLatticeAction from 'https://cdn.latticegrid.dev/lattice-grid@1.108.0/modules/svelte.esm.min.js';
const lattice = createLatticeAction({ createGrid });
const config = {
rowKey: 'id',
highlightOnChange: { duration: 500 },
// "Mark all" resets every baseline to now, so the deltas and the rank
// change start again from the current book.
toolPanel: {
side: 'left', panels: ['columns', 'filters'],
actions: [{ name: 'rebase', title: 'Mark all', icon: 'flag',
run: ({ grid }) => grid.statistics.rebase('price') }],
},
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' },
{ id: 'quartile', title: 'Quartile', shadow: { of: 'price', kind: 'quartile' }, type: 'number' },
],
// Land sorted on the movers.
state: { sort: [{ col: 'moved', dir: 'desc' }] },
rows,
};
</script>
<svelte:head>
<link rel="stylesheet" href="https://cdn.latticegrid.dev/lattice-grid@1.108.0/lattice-grid.min.css">
</svelte:head>
<div use:lattice={config} style="height: 460px"></div>