demo D209
A unit family of your own in Angular
Register a unit system from symbols and their factors
registerUnitSystem · createUnitType
This grid registers a unit family of your own from its symbols and their conversion factors, then uses it like any built-in unit type. It lets a column speak a domain's own units, parsed and converted correctly, without waiting for the unit to be built in.
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, registerUnitSystem, defineUnit, createUnitType } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import { LatticeGridComponent, provideLattice } from '@toclocoinc/lattice-grid/angular';
// A unit family of your own. factor is how many base units one of these is;
// exactly one must be 1. The factors are the ladder, sorted at load.
registerUnitSystem('yarn', [
defineUnit('tex', 1, ['tx']),
defineUnit('ktex', 1e3, [], { prefix: 'k' }),
defineUnit('den', 1 / 9, ['denier']),
]);
const dataTypes = {
linearDensity: createUnitType({ system: 'yarn', unit: 'tex', display: 'auto' }),
};
const columns = [
{ field: 'yarn', title: 'Yarn', layout: { pin: 'start', width: 130 } },
{ field: 'count', title: 'Linear density', type: 'linearDensity', total: 'median' },
];
// 1500 tex renders as 1.5 ktex; typing "9 den" stores 1.
const rows = [/* yarn records */];
@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 })],
});