demo D197
Running totals in Angular
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 Angular version. A standalone component takes the whole configuration through one config input, surfaces grid events as outputs, and exposes the live grid on a getter for anything the inputs do not cover.
The configuration
import { Component } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { createGrid } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import { LatticeGridComponent, provideLattice } from '@toclocoinc/lattice-grid/angular';
const 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 } },
];
const rows = [/* dated amounts */];
@Component({
selector: 'app-root',
standalone: true,
imports: [LatticeGridComponent],
template: '<lattice-grid [config]="grid" style="display:block;height:460px"></lattice-grid>',
})
export class AppComponent {
grid = {
rowKey: 'id',
columns: columns,
state: { sort: [{ col: 'date', dir: 'asc' }] },
rows: rows,
};
}
bootstrapApplication(AppComponent, {
providers: [provideLattice({ createGrid })],
});