demo D184
Shadow columns: what changed in Vue
Delta, percent change and a move count against the value at page load
shadow: { of, kind: 'delta' }
This grid adds shadow columns showing each value's delta, percent change and move count against its value at page load. It lets a reader see what has moved since they arrived, as real sortable columns beside the live figures.
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',
highlightOnChange: { duration: 500 },
columns: [
{ field: 'symbol', title: 'Symbol', layout: { pin: 'start', width: 120 } },
{ field: 'desk', title: 'Desk', filter: { type: 'set' } },
{ field: 'region', title: 'Region', filter: { type: 'set' } },
{ field: 'price', title: 'Price', type: 'number' },
// A shadow column is declared against another and maintained by the grid.
{ id: 'delta', title: 'Change', shadow: { of: 'price', kind: 'delta' }, type: 'number', format: { signed: true } },
{ id: 'pct', title: 'Change %', shadow: { of: 'price', kind: 'deltaPercent' }, type: 'number', format: { style: 'percent', signed: true } },
{ id: 'moves', title: 'Moves', shadow: { of: 'price', kind: 'updates' }, type: 'number' },
{ id: 'streak', title: 'Streak', shadow: { of: 'price', kind: 'streak' }, type: 'number', format: { signed: true } },
],
rows, // one symbol per row: symbol, desk, region, price
},
};
},
mounted() {
// A shadow column measures against the value each row had at page load, so
// it needs a live feed to show anything. This nudges a slice of the book on
// a timer and pushes the changes with rows.apply; every shadow updates from
// that call.
const grid = this.$refs.grid.grid();
this.timer = setInterval(() => {
const updates = rows.slice(0, 40).map((r) => ({
id: r.id,
price: Math.round(r.price * (1 + (Math.random() - 0.5) * 0.02) * 1e4) / 1e4,
}));
grid.rows.apply({ update: updates });
}, 120);
},
unmounted() {
clearInterval(this.timer);
},
template: '<lattice-grid ref="grid" v-bind="config" />',
}).mount('#grid');
</script>