Lattice Grid Buy a licence

demo D187

Marking a baseline in React

"Mark all" resets every delta to now

grid.statistics.rebase(col)

This grid resets every delta to now with a single 'mark all', setting a fresh baseline. It lets a reader say 'watch from here', so change tracking restarts from the current moment rather than page load.

Building…
Loading a live grid…

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="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.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' },
    { 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>