Lattice Grid Buy a licence

demo D197

Running totals

The one derived value that depends on the display order

running: { of, kind: 'total' }

Building…
Loading a live grid…

The configuration

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.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.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/lattice-grid.esm.min.js';
  import createLatticeGrid from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/modules/react.esm.min.js';

  const LatticeGrid = createLatticeGrid({ React, createGrid });

  const columns = [
    { field: 'date', title: 'Date', type: 'date', layout: { pin: 'start', width: 150 } },
    { field: 'amount', title: 'Amount', type: 'number', total: 'sum' },
    // A running total depends on the display order, so it is running, not shadow.
    { id: 'cum', title: 'Running', running: { of: 'amount', kind: 'total' }, type: 'number' },
    { id: 'share', title: 'Cumulative %', running: { of: 'amount', kind: 'percent' }, type: 'number', format: { style: 'percent' } },
  ];

  const rows = [/* dated amounts */];

  function App() {
    return (
      <LatticeGrid
        rowKey="id"
        columns={columns}
        state={{ sort: [{ col: 'date', dir: 'asc' }] }}
        rows={rows}
        style={{ height: '460px' }}
      />
    );
  }

  createRoot(document.getElementById('grid')).render(<App />);
</script>