demo D179
Statistics in the totals row in Vue
Median, percentiles, deviation and spread, each over the filtered rows
total: 'median' · 'p95' · 'stddev'
This grid puts statistics in the totals row, median, percentiles, standard deviation and spread, each computed over the filtered rows. It gives a footer that summarises the shape of a column, not just its sum, and follows the filter as it changes.
This is the Vue 3 version. A createLatticeGrid component takes the configuration through v-bind, and reactive data flows straight into the grid, so it updates the way the rest of your Vue app does.
The configuration
<link rel="stylesheet" href="https://cdn.latticegrid.dev/lattice-grid@1.108.0/lattice-grid.min.css">
<style>
#grid > div { height: 460px; }
</style>
<div id="grid"></div>
<script type="module">
import * as Vue from 'https://esm.sh/vue@3/dist/vue.esm-browser.prod.js';
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/vue.esm.min.js';
const LatticeGrid = createLatticeGrid({ vue: Vue, createGrid });
Vue.createApp({
components: { LatticeGrid },
data() {
return {
config: {
rowKey: 'id',
columnDefaults: { filter: true },
columns: [
{ field: 'symbol', title: 'Symbol', layout: { pin: 'start', width: 120 } },
{ field: 'desk', title: 'Desk', filter: { type: 'set' } },
// The reduction is named per column and the title says which one, so the
// footer reads as what it is. Each figure is over the filtered rows, so
// filtering a desk moves every one of them.
{ field: 'price', title: 'Price / median', type: 'number', format: { decimals: 4 }, total: 'median' },
{ field: 'bid', title: 'Bid / p95', type: 'number', format: { decimals: 4 }, total: 'p95' },
{ field: 'change', title: 'Change / stddev', type: 'number', format: { style: 'percent', decimals: 2 }, total: 'stddev' },
{ field: 'volume', title: 'Volume / IQR', type: 'number', format: { notation: 'compact' }, total: 'iqr' },
{ field: 'notional', title: 'Notional / sum', type: 'number',
format: { style: 'currency', currency: 'USD', decimals: 2 }, total: 'sum' },
],
rows, // trading book: symbol, desk, price, bid, change, volume, notional
},
};
},
template: '<lattice-grid v-bind="config" />',
}).mount('#grid');
</script>