demo D07
Type inference
Undeclared columns that still sort the way you would expect
default comparator
The configuration
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.13.0/lattice-grid.min.css">
<script src="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.13.0/lattice-grid.min.js"></script>
<div id="grid" style="height: 540px"></div>
<script>
// No `type` on any column. The default comparator is value-aware, so a text
// column of numbers still orders 2.5 before 10 and dates sort chronologically.
// Declaring a type is what buys the editor, the parser, the export format and
// the filter kind, so it is worth doing once a column earns it.
const grid = LatticeGrid.createGrid(document.getElementById('grid'), {
rowKey: 'id',
columns: [
{ field: 'service', title: 'Service' },
{ field: 'active', title: 'Active' },
{ field: 'instances', title: 'Instances' },
{ field: 'errorRate', title: 'Error rate' },
{ field: 'monthlyCost', title: 'Monthly cost' },
{ field: 'lastDeploy', title: 'Last deploy' },
],
rows, // objects with mixed, undeclared value types
});
</script>
Sorting undeclared columns correctly by default
A JavaScript data grid usually asks for a type per column before it can sort or filter sensibly. Lattice Grid also works without that step. When a column has no declared type, it samples the values already in the row set and picks a default comparator: numbers compare numerically, ISO-shaped strings compare as dates, and everything else falls back to locale-aware text collation rather than byte order. The result is a grid that sorts a currency column, a date column and a plain string column the way a person would expect, even when the columns were never described in configuration.
Reach for this when the shape of the data is not known in advance, for instance a generic table renderer fed by an arbitrary JSON payload, or a prototype where declaring twenty columns up front would slow down the first pass. The default comparator only runs the inference once per column, caching the outcome, so scrolling and re-sorting a large result set does not repeat the sampling work. Declaring type explicitly always takes precedence and skips inference entirely, which is the better choice once a column’s shape is fixed and worth the extra line.
Does Lattice Grid need a schema before it can sort a column?
No. Lattice Grid samples row values for any column without a declared type and chooses a comparator from that sample, numeric, date-like or text. A schema is optional, not required. Declaring type on a column overrides the inferred comparator and is worth doing once the data shape is settled, since it removes the sampling step and documents the intent for anyone reading the configuration later.