demo D146
Pinned rows in Angular
A grand total pinned below the scrolling body
grandTotalRow: 'bottom'
This grid fixes a grand total row below the scrolling body so it stays visible wherever the reader has scrolled. It keeps the figure a reader is really after in view at all times, rather than at the far end of a long table.
In Angular, the pinned row in this demo is a grand total: grandTotalRow set to 'bottom' inside the config input of the standalone LatticeGridComponent. It holds the Monthly cost sum under the scrolling body while a reader works through a long list of cloud cost rows. Rows of your own, such as a units line or a target, go in through pinnedTopRows and pinnedBottomRows in the same config. The Angular code underneath is the demo's configuration, with the npm install and import lines above it and the notes after it on changing pinned rows at run time.
Install and import
npm install @toclocoinc/lattice-grid
# free on localhost; a production domain needs a licence key (see /pricing/)
import { createGrid } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import { LatticeGridComponent, provideLattice } from '@toclocoinc/lattice-grid/angular';
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: 'account', title: 'Account', filter: { type: 'set' } },
{ field: 'service', title: 'Service', filter: { type: 'set' } },
{ field: 'resource', title: 'Resource', layout: { flex: 1, min: 200, max: 320 } },
{ field: 'region', title: 'Region', filter: { type: 'set' } },
{ field: 'environment', title: 'Env', filter: { type: 'set' },
cell: { decoration: 'pill', variant: { map: {
prod: 'danger', 'prod-2': 'danger', 'definitely-prod': 'danger',
staging: 'warning', untagged: 'warning', test: 'info',
dev: 'success', 'not-prod': 'neutral',
} } } },
{ field: 'change', title: 'Change', type: 'number',
layout: { width: 140, min: 140 }, format: { style: 'percent', decimals: 1 } },
{ field: 'cost', title: 'Monthly cost', type: 'number', layout: { width: 170 },
format: { style: 'currency', currency: 'USD', decimals: 2 }, total: 'sum' },
];
const rows = [/* 200,000 cloud cost records */];
@Component({
selector: 'app-root',
standalone: true,
imports: [LatticeGridComponent],
template: '<lattice-grid [config]="grid" style="display:block;height:540px"></lattice-grid>',
})
export class AppComponent {
grid = {
rowKey: 'id',
selection: 'multiple',
grandTotalRow: 'bottom',
toolPanel: { side: 'left', panels: ['columns', 'filters', 'views', 'quick'],
actions: ['undo', 'redo', 'export', 'restore', 'maximise'], exportName: 'lattice-demo' },
columns: columns,
rows: rows,
};
}
bootstrapApplication(AppComponent, {
providers: [provideLattice({ createGrid })],
});
API notes for pinned rows in Angular
- What the demo uses.
grandTotalRow: 'bottom'in thegridfield pins the grand total beneath the viewport, so it stays in view while the rows scroll and is not counted byrows.count(). Thecostcolumn’stotal: 'sum'supplies the figure. - Which property pins your own rows.
pinnedTopRowsholds rows above the scrolling body andpinnedBottomRowsholds rows below it. Each takes an array of plain objects, drawn through the ordinary column pipeline, so formatters and cell renderers apply. The demo’s snippet does not use either one; they are the configuration keys the grid documents for this. - Passing them in.
[config]takes every configuration key, sopinnedTopRowssits besidecolumnsandrowsin the object. Inputs are compared by identity and never rebuild the grid, so a changed[config]reaches the grid already on screen. An inline[config]="{ ... }"is a new object on every pass: hold the configuration in a field or a signal, as the demo’sgridfield does. - Updating at run time. Pass a new array. The grid tells a changed pinned set by array identity, so pushing into the array you passed before will not repaint. With the grid from
viewChildor(grid-ready),grid.setPinnedRows(rows, { edge: 'top' })does the same, andgetPinnedRows({ edge })returns a copy. - Sorting and filtering. Pinned rows are not counted, sorted, filtered, grouped, selectable or exported. A filter that matches nothing still leaves them visible. At the bottom edge the grand total comes first and your rows sit below it.
- Order and height. Rows appear in array order, and their height comes from
rowHeight. Give the<lattice-grid>element a height, as the demo’sheight:540pxdoes.
How do I change a pinned row from an Angular component?
Keep the configuration in a signal or a field and replace it with a new object whose pinnedTopRows is a new array. The input change is pushed into the live grid from ngOnChanges. Or take the grid from (grid-ready) and call setPinnedRows(). Read the grid from an event handler, not ngAfterViewInit, because the grid paints on its own schedule rather than Angular’s.
Does a pinned row take part in sorting or filtering in Angular?
No. Pinned rows sit outside the data, so counting, sorting, filtering, grouping, selection and export do not include them. The grand total differs in kind: it is computed from the rows, so it follows the filter, and with 'bottom' it still stays out of rows.count().
Does a pinned row work with OnPush or zoneless change detection?
Yes. The component owns one element, builds the grid after render and pushes changed inputs in from ngOnChanges, so a host on OnPush still gets a live grid. The grid is created outside the zone, and an output you have bound re-enters it so your view repaints.
Pinning a totals row below the scrolling body
Pinned rows fix a row, or a small set of rows, outside the scrolling body of a JavaScript data grid so it stays visible regardless of where the reader has scrolled the rest of the data. A grand total is the common case: a reader scans a few thousand line items, and the sum, average or count at the foot of the column needs to sit in view the whole time rather than requiring a scroll to the bottom to check it. Lattice Grid controls this through grandTotalRow: 'bottom', which renders an aggregated row anchored beneath the scrolling body. The same idea extends to a row of your own choosing rather than an aggregated total: pinnedTopRows and pinnedBottomRows pin whatever objects you pass, rendered through the ordinary column pipeline but excluded from counting, sorting, filtering and export. See the step-by-step how to pin rows to the top of a grid guide for a runnable example and the source.
The pinned row shares column widths, alignment and pinned-column regions with the scrolling body, so a total lines up under its column without separate configuration, including when that column itself is pinned to the left or right edge. It sits outside the virtualised row set, so it does not shift position as the body is scrolled, resized or filtered. For screen reader users, the pinned row keeps its place in the grid’s row and column model, so assistive technology reports it by its actual row role rather than as a detached decoration outside the data.
How do you pin a totals row to the bottom of a data grid?
Set grandTotalRow: 'bottom' in the grid configuration. Lattice Grid renders the aggregated row outside the scrolling body, anchored to the bottom edge, sharing the same column widths and pinned regions as the rows above it. For a row anchored above the body, pass your own computed row in pinnedTopRows.