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">
<style>
  #grid > div { height: 440px; }
  #out { margin-top: 12px; font-family: monospace; }
</style>
<div id="app"></div>

<script type="module">
  import * as Vue from 'https://esm.sh/vue@3';
  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/vue.esm.min.js';

  const LatticeGrid = createLatticeGrid({ vue: Vue, createGrid });

  Vue.createApp({
    components: { LatticeGrid },
    data() {
      return {
        config: {
          rowKey: 'id',
          selection: { mode: 'multiple', ranges: true },
          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' },
          ],
          rows,  // trading book records
        },
      };
    },
    mounted() {
      // The component exposes the live grid via a template ref. Drag a block of
      // numeric cells and the summary reads off that range as it changes.
      const grid = this.$refs.grid.grid();
      const out = document.getElementById('out');
      grid.on('range:changed', () => {
        const s = grid.selection.statistics();
        out.textContent = s
          ? s.cells + ' cells · median ' + s.median + ' · q1 ' + s.q1 + ' · q3 ' + s.q3 + ' · sd ' + s.stddev
          : 'Select a block of numeric cells';
      });
    },
    template: `
      <div id="grid"><lattice-grid ref="grid" v-bind="config" /></div>
      <div id="out">Select a block of numeric cells</div>
    `,
  }).mount('#app');
</script>