demo D184
Shadow columns: what changed in React
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.
This is the React version. The grid mounts through the createLatticeGrid adapter, which takes its configuration as ordinary props and hands back the live grid through a ref. The grid below is the same one every other tab runs.
The configuration
<link rel="stylesheet" href="https://cdn.latticegrid.dev/lattice-grid@1.108.0/lattice-grid.min.css">
<div id="grid"></div>
<script type="module">
import React from 'https://esm.sh/react@18';
import { createRoot } from 'https://esm.sh/react-dom@18/client';
import { createGrid } from 'https://cdn.latticegrid.dev/lattice-grid@1.108.0/lattice-grid.esm.min.js';
import createLatticeGrid from 'https://cdn.latticegrid.dev/lattice-grid@1.108.0/modules/react.esm.min.js';
const LatticeGrid = createLatticeGrid({ React, createGrid });
const columns = [
{ field: 'symbol', title: 'Symbol', layout: { pin: 'start', width: 120 } },
{ field: 'price', title: 'Price', type: 'number' },
// A shadow column is declared against another and maintained by the grid.
{ id: 'delta', title: 'Change', shadow: { of: 'price', kind: 'delta' }, type: 'number', format: { signed: true } },
{ id: 'pct', title: 'Change %', shadow: { of: 'price', kind: 'deltaPercent' }, type: 'number', format: { style: 'percent', signed: true } },
{ id: 'moves', title: 'Moves', shadow: { of: 'price', kind: 'updates' }, type: 'number' },
{ id: 'streak', title: 'Streak', shadow: { of: 'price', kind: 'streak' }, type: 'number', format: { signed: true } },
];
const rows = [/* a live price book */];
function App() {
return (
<LatticeGrid
rowKey="id"
highlightOnChange={{ duration: 500 }}
columns={columns}
rows={rows}
style={{ height: '460px' }}
/>
);
}
createRoot(document.getElementById('grid')).render(<App />);
</script>