demo D187
Marking a baseline
"Mark all" resets every delta to now
grid.statistics.rebase(col)
Loading a live grid…
The configuration
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.28.0/lattice-grid.min.css">
<div id="app"></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.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.28.0/lattice-grid.esm.min.js';
import createLatticeGrid from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.28.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' },
{ id: 'delta', title: 'Change', shadow: { of: 'price', kind: 'delta' }, type: 'number', format: { signed: true } },
{ id: 'first', title: 'Baseline', shadow: { of: 'price', kind: 'firstValue' }, type: 'number' },
];
const rows = [/* a live price book */];
function App() {
const gridRef = React.useRef(null);
// rebase moves every baseline to the current value, so the deltas start again.
const markAll = () => {
const grid = gridRef.current && gridRef.current.grid;
if (grid) grid.statistics.rebase('price');
};
return (
<>
<button onClick={markAll}>Mark all</button>
<LatticeGrid
ref={gridRef}
rowKey="id"
columns={columns}
rows={rows}
style={{ height: '440px', marginTop: '8px' }}
/>
</>
);
}
createRoot(document.getElementById('app')).render(<App />);
</script>