demo D208
Configuring a type in Svelte
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 Svelte version. A use action attaches the grid to a plain element, so no framework runtime is passed in and the component stays small, while the configuration is ordinary Svelte state.
The configuration
<script>
import { createGrid, createUnitType } from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/lattice-grid.esm.min.js';
import createLatticeAction from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/modules/svelte.esm.min.js';
const lattice = createLatticeAction({ createGrid });
// 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 config = {
rowKey: 'id',
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' },
],
rows,
};
</script>
<svelte:head>
<link rel="stylesheet" href="https://cdn.latticegrid.dev/lattice-grid@1.107.0/lattice-grid.min.css">
</svelte:head>
<div use:lattice={config} style="height: 460px"></div>