demo D184
Shadow columns: what changed: JavaScript Data Grid Demo
Delta, percent change and a move count against the value at page load
shadow: { of, kind: 'delta' }
This grid adds shadow columns showing each value's delta, percent change and move count against its value at page load. It lets a reader see what has moved since they arrived, as real sortable columns beside the live figures.
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 },
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 } },
// Every value is against the price the row had at page load.
{ id: 'delta', title: 'Change since open', shadow: { of: 'price', kind: 'delta' }, type: 'number', format: { decimals: 4, signed: true }, layout: { width: 150 } },
{ id: 'deltaPct', title: 'Change %', shadow: { of: 'price', kind: 'deltaPercent' }, type: 'number', format: { style: 'percent', decimals: 2, signed: true }, layout: { width: 120 } },
{ id: 'updates', title: 'Moves', shadow: { of: 'price', kind: 'updates' }, type: 'number', layout: { width: 100 } },
{ id: 'streak', title: 'Streak', shadow: { of: 'price', kind: 'streak' }, type: 'number', format: { signed: true }, layout: { width: 100 } },
],
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>