demo D208
Configuring a type in Angular
One field, five presentations; the stored value never changes
createUnitType({ display, decimals, … })
This grid shows one stored field presented five different ways, with the underlying value never changing. It shows that display is a setting, not a rewrite, so you can change decimals, symbols or format without touching the data behind the column.
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, createUnitType } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import { LatticeGridComponent, provideLattice } from '@toclocoinc/lattice-grid/angular';
// The same field stored in metres, shown four ways. The stored value never
// changes; only the display does.
const dataTypes = {
spanAuto: createUnitType({ system: 'length', unit: 'm', display: 'auto' }),
spanMm: createUnitType({ system: 'length', unit: 'm', display: 'mm' }),
spanKm: createUnitType({ system: 'length', unit: 'm', display: 'km', decimals: 3 }),
spanSig: createUnitType({ system: 'length', unit: 'm', display: 'auto', significantFigures: 3 }),
};
const columns = [
{ field: 'run', title: 'Run', layout: { pin: 'start', width: 120 } },
{ field: 'span', id: 'stored', title: 'Stored (m)', type: 'number' },
{ field: 'span', id: 'auto', title: "display: 'auto'", type: 'spanAuto' },
{ field: 'span', id: 'mm', title: "display: 'mm'", type: 'spanMm' },
{ field: 'span', id: 'km', title: "display: 'km'", type: 'spanKm' },
{ field: 'span', id: 'sig', title: '3 sig figs', type: 'spanSig' },
];
const rows = [/* runs, each with a span in metres */];
@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',
dataTypes: dataTypes,
columns: columns,
rows: rows,
};
}
bootstrapApplication(AppComponent, {
providers: [provideLattice({ createGrid })],
});