Lattice Grid Buy a licence

demo D199

Statistics of a selection

Drag a rectangle; it is summarised as one set of figures

grid.selection.statistics()

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="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.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: 'symbol', title: 'Symbol', layout: { pin: 'start', width: 120 } },
    { field: 'desk', title: 'Desk', filter: { type: 'set' } },
    { field: 'price', title: 'Price', type: 'number' },
    { field: 'bid', title: 'Bid', type: 'number' },
    { field: 'volume', title: 'Volume', type: 'number' },
    { field: 'notional', title: 'Notional', type: 'number',
      format: { style: 'currency', currency: 'USD' }, total: 'sum' },
  ];

  const rows = [/* trading book records */];

  function App() {
    const gridRef = React.useRef(null);
    const [out, setOut] = React.useState('Select a block of numeric cells');

    // Drag a range of numeric cells: selection.statistics() returns the count,
    // median, quartiles and standard deviation for the block, read from the
    // live grid whenever the range changes.
    const report = () => {
      const grid = gridRef.current && gridRef.current.grid;
      const s = grid && grid.selection.statistics();
      setOut(s
        ? s.cells + ' cells, median ' + s.median + ', q1 ' + s.q1 + ', q3 ' + s.q3 + ', sd ' + s.stddev
        : 'Select a block of numeric cells');
    };

    return (
      <>
        <LatticeGrid
          ref={gridRef}
          rowKey="id"
          selection={{ mode: 'multiple', ranges: true }}
          columns={columns}
          rows={rows}
          onRangeChanged={report}
          style={{ height: '440px' }}
        />
        <div style={{ marginTop: '12px', fontFamily: 'monospace' }}>{out}</div>
      </>
    );
  }

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