demo D197
Running totals in Vue
The one derived value that depends on the display order
running: { of, kind: 'total' }
This grid shows a running total, the one derived value that depends on the display order, accumulating down the rows. It gives a cumulative figure that reads correctly in sequence, so a balance or a tally builds row by row.
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.107.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.107.0/lattice-grid.esm.min.js';
import createLatticeGrid from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/modules/vue.esm.min.js';
const LatticeGrid = createLatticeGrid({ vue: Vue, createGrid });
Vue.createApp({
components: { LatticeGrid },
data() {
return {
config: {
rowKey: 'id',
columns: [
{ field: 'date', title: 'Date', type: 'dateString', layout: { pin: 'start', width: 150 } },
{ field: 'amount', title: 'Amount', type: 'number', format: { style: 'currency', currency: 'USD' }, 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', format: { style: 'currency', currency: 'USD' } },
{ id: 'share', title: 'Cumulative %', running: { of: 'amount', kind: 'percent' }, type: 'number', format: { style: 'percent', decimals: 1 } },
],
state: { sort: [{ col: 'date', dir: 'asc' }] },
rows,
},
};
},
template: '<lattice-grid v-bind="config" />',
}).mount('#grid');
</script>