demo D185
Shadow columns: rank and movement: JavaScript Data Grid Demo
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.
Loading a live grid…
The configuration
<link rel="stylesheet" href="https://cdn.latticegrid.dev/lattice-grid@1.103.2/lattice-grid.min.css">
<script src="https://cdn.latticegrid.dev/lattice-grid@1.103.2/lattice-grid.min.js"></script>
<div id="grid" style="height: 460px"></div>
<script>
const grid = LatticeGrid.createGrid(document.getElementById('grid'), {
rowKey: 'id',
// Flash a cell for half a second when its value moves.
highlightOnChange: { duration: 500 },
toolPanel: {
side: 'left', panels: ['columns', 'filters'],
// Mark all: reset every baseline to the current book, so the deltas and
// the rank change start again from now.
actions: [{ name: 'rebase', title: 'Mark all', icon: 'flag',
run: ({ grid }) => grid.statistics.rebase('price') }],
},
// Land sorted on the top movers: the live top-movers view.
state: { sort: [{ col: 'moved', dir: 'desc' }] },
columns: [
{ field: 'symbol', title: 'Symbol', layout: { pin: 'start', width: 120 } },
{ field: 'desk', title: 'Desk', filter: { type: 'set' } },
{ field: 'region', title: 'Region', filter: { type: 'set' } },
{ field: 'price', title: 'Price', type: 'number', format: { decimals: 4 } },
// Rank is over every tracked row, so the order is stable as the feed runs;
// rankChange is places moved since the baseline, positive for a climber.
{ id: 'rank', title: 'Rank', shadow: { of: 'price', kind: 'rank' }, type: 'number', layout: { width: 90 } },
{ id: 'moved', title: 'Places moved', shadow: { of: 'price', kind: 'rankChange' }, type: 'number', format: { signed: true }, layout: { width: 140 } },
{ id: 'pct', title: 'Percentile', shadow: { of: 'price', kind: 'percentile' }, type: 'number', format: { decimals: 0, suffix: 'th' }, layout: { width: 120 } },
{ id: 'quartile', title: 'Quartile', shadow: { of: 'price', kind: 'quartile' }, type: 'number', layout: { width: 110 } },
],
rows, // trading book: symbol, desk, region, price
});
setInterval(() => {
const updates = rows.slice(0, 40).map((r) => ({
id: r.id,
price: Math.round(r.price * (1 + (Math.random() - 0.5) * 0.02) * 1e4) / 1e4,
}));
grid.rows.apply({ update: updates });
}, 120);
</script>