demo D208
Configuring a type
One field, five presentations; the stored value never changes
createUnitType({ display, decimals, … })
Loading a live grid…
The configuration
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.28.0/lattice-grid.min.css">
<script type="module">
import { defineLatticeGrid } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.28.0/modules/webcomponent.esm.js';
defineLatticeGrid();
</script>
<lattice-grid row-key="id" style="display: block; height: 460px"></lattice-grid>
<script type="module">
import { createUnitType } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.28.0/modules/webcomponent.esm.js';
// The same field stored in metres, shown four ways. The stored value never
// changes; only the display does. The unit type comes from the element's own
// module so its columns recognise it.
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 grid = document.querySelector('lattice-grid');
grid.config = {
dataTypes,
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' },
],
};
grid.rows = rows;
</script>