api reference
Lattice Grid API reference
How to construct a grid, the configuration and column specs, and the grid methods. Each namespace has its own page below; the full reference is one archive away.
Version 1.13.0 Zero dependencies Developer guide →
Construction
Two files are all you need: a stylesheet and a script. Nothing is fetched at runtime (no CDN, no font, no icon sprite) however the two files themselves got there.
<!-- Script tag, from your own build. Everything is on one global. -->
<link rel="stylesheet" href="dist/lattice-grid.min.css">
<script src="dist/lattice-grid.min.js"></script>
<script>
const grid = LatticeGrid.createGrid(document.getElementById('grid'), config);
</script>
Or straight from jsDelivr, no npm install, no bundler, no local copy at all:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.7.1/lattice-grid.min.css">
<script src="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.7.1/lattice-grid.min.js"></script>
<script>
const grid = LatticeGrid.createGrid(document.getElementById('grid'), config);
</script>
Or as modules, importing the bundle by path: your own build, npm, or jsDelivr:
// With a renderer, in a browser. Any of:
import { createGrid } from './dist/lattice-grid.esm.js';
// import { createGrid } from '@toclocoinc/lattice-grid';
// import { createGrid } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.7.1/lattice-grid.esm.min.js';
const grid = createGrid(document.getElementById('grid'), config);
// Headless: the same API without a renderer. Data, filters, sort,
// grouping, totals, formatting and export all work; grid.element is
// null and the DOM-only chrome is simply absent.
// Runs in Node, for tests and server-side export.
import { createHeadlessGrid } from '@toclocoinc/lattice-grid';
const grid = createHeadlessGrid(config);
jsDelivr mirrors every version published to npm at
cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@<version>/<file>. Pin an exact
version for anything shipped: @1.7.1, not @latest, so a release does
not change what a page already in production loads. The same convention reaches any module:
.../modules/htmx.esm.min.js, .../modules/react.esm.min.js, and so on.
Configuration properties
Every key is settable at runtime through grid.set(key, value). Keys marked
dom are read by createGrid and ignored by a headless grid.
Data and structure
| Property | Type | Default | Description |
|---|---|---|---|
| columns | (Column | ColumnGroup)[] | , | Column definitions. Groups may nest. |
| columnGroups | ColumnGroup[] | , | Header grouping declared separately from the columns. |
| rows | unknown[] | , | Row objects. Held by reference; not copied. |
| rowKey | string | (row) => string | , | Stable row identity. Without it the grid assigns a key per row object and warns: enough for sorting, filtering, selection and copying within a session, but change tracking, streaming dedupe, selection persistence and remote reload all switch off, because new objects are new rows. |
| source | SourceConfig | memory | Where rows come from: memory, paged, remote or stream. See Sources. |
| tree | TreeConfig | , | { path } or { parentKey }, plus label, orphans. Rows form a hierarchy. See Tree data. |
| detail | DetailConfig | , | { rows, config, render, isMaster, height, cacheLimit, target }. A master row expands into a nested grid, inline or into an element you supply. See Master-detail. |
| context | unknown | , | Arbitrary value passed to every callback, so formatters and renderers need no closures over app state. |
Defaults and registries
| Property | Type | Description |
|---|---|---|
| columnDefaults | Column | Merged under every column before its own definition. |
| columnPresets | Record<string, Column> | Named bundles applied with preset: 'money'. |
| dataTypes | Record<string, DataType> | Custom types. Registered ahead of the built-ins, so a name here overrides one of ours. |
| sampleSize | number | Values read per undeclared column when inferring its type. Default 100. |
| targetSize | 'default' | 'large' | Raises every interactive target to a comfortable size for touch, leaving the type alone. Applied automatically on a coarse pointer; 'default' opts out of that. |
| components | Record<string, Ctor> | Renderers, editors and filters addressable by name. |
| pipes | Record<string, fn> | Template pipes for cell.template. |
| totalFns | Record<string, TotalFn> | Custom aggregations, addressable from column.total. |
| variants | Record<string, VariantDefinition> | Semantic colour tokens for decorations. |
Behaviour
| Property | Type | Default | Description |
|---|---|---|---|
| selection | SelectionConfig | 'single' | 'multiple' | 'none' | , | Object form adds checkbox (a pinned column of row checkboxes), headerCheckbox (tri-state select-all in its heading), groupSelectsChildren, ranges, fillHandle, fill. See Selection and ranges. |
| edit | EditConfig | boolean | , | { enabled, mode: 'cell' | 'row', start: 'single' | 'double' | 'key', enterMovesDown, undoDepth, commit, confirm, pendingTimeout }. The last three turn on optimistic writes. |
| pagination | PaginationConfig | boolean | , | Local or remote paging. |
| quickFilterText | string | , | Initial quick-filter term. Equivalent to grid.filters.quick(text). |
| hostFilter | { active(), passes(row) } | , | An application-level predicate composed with the grid's own filters. |
| pivot | object | , | { enabled, groupTotals, totalsLabel, maxColumns, separator }. groupTotals: 'before' | 'after' adds a column group totalling every value column across all pivot values, at the near or far edge; omitted, it adds none. totalsLabel heads it, defaulting to Total. maxColumns defaults to 500, counts the totals group, and fails with a message rather than locking the browser. |
| grandTotalRow | boolean | 'bottom' | false | true puts it inline at the end of the rows; 'bottom' pins it above the status bar. Maintained incrementally on a memory source: see Grouping, totals and pivot. |
| pinnedTopRows | object[] | , | Rows held above the scrolling body. Rendered through the ordinary column pipeline, but not part of the data: not counted, sorted, filtered, grouped, selectable or exported. See Pinned rows. |
| pinnedBottomRows | object[] | , | As pinnedTopRows, held below the body instead. Sits under the grand total when both are shown. |
| fullWidth | { when, render } | , | Draw matching rows as one band across every column instead of dividing them into columns, a section banner, a note, a “load more” affordance. when(row) picks them, render(params) fills them. Still ordinary data rows in every other respect. See Full-width rows. |
| groupFooter | boolean | false | A closing total row per group. |
| totalFilteredOnly | boolean | true | Totals reduce the filtered set. false totals the whole dataset, group totals included. See Grouping, totals and pivot. |
| totalOnlyChangedColumns | boolean | false | Reduce only the totalled columns an edit actually changed. Off by default, it asserts that each total depends on nothing but its own column. See Grouping, totals and pivot. |
| showTotalInHeader | boolean | true | Under grouping or pivot, a totalled column's heading names its reduction on a line above the column name. See Grouping, totals and pivot. |
| allowUnsafeTemplates | boolean | false | Off by default. Templates are escaped unless this is explicitly set. When set, an interpolated value may contain presentational markup, but script is still removed from it: <script>, <iframe> and the other executable tags, on* handler attributes, and javascript: URLs. The flag permits markup, not code. |
| licence | string | , | Signed licence key. Removes the trial watermark; unlocks nothing, because nothing is locked. |
Presentation
| Property | Type | Default | Description |
|---|---|---|---|
| messages | object | en-GB | Replaces the grid's own text: labels, menus and screen-reader announcements. A partial catalogue laid over the built-in British English one, so anything you leave out stays in English. Twenty catalogues are bundled: EN_GB, EN_US, FR_FR, FR_CA, IT_IT, ES_ES, PT_BR, DE_DE, NL_NL, SV_SE, DA_DK, NB_NO, FI_FI, PL_PL, CS_CZ, HU_HU, RO_RO, UK_UA, EL_GR, JA_JP and AR. They are exports of the package, not separate files, so importing one does not reduce what is bundled. EN_US is a partial overlay carrying only what differs from British English. AR_SA is an alias for AR: the Arabic catalogue is pan-Arabic, and a region appears in a name only where two variants ship. resolveCatalogue(tag) finds the catalogue for any tag, so resolveCatalogue('es-MX') returns the Spanish one. Every key is listed in MESSAGE_KEYS; auditCatalogue() reports what a catalogue of your own is missing. |
| locale | string | runtime | BCP-47. Drives every formatter and one shared Intl.Collator. |
| direction | 'ltr' | 'rtl' | 'auto' | auto | Writing direction. Left unset, it follows the element's computed dir and then the locale, so locale: 'ar' renders right to left without further configuration. Set it explicitly to override both. |
| theme | 'light' | 'dark' | 'high-contrast' | 'terminal' | , | Stamped as data-theme on the grid's root. Unset follows the viewer's prefers-color-scheme. See Theming. |
| density | 'compact' | 'standard' | 'comfortable' | 'spacious' | number | 'compact' | One scale that every geometry token derives from: row height, spacing, decoration sizes, and type at a damped rate. Row heights are 23.8 / 28 / 42 / 56px. A number scales 28px, so 1.4 gives 39.2px for anything between the presets. Virtualisation follows it; an explicit rowHeight overrides it. |
| rowHeight | number | (row) => number | 28 | A function enables variable-height rows. |
| headerHeight | number | 32 | Per header row. |
| title | string | , | A caption drawn above the column headings. Inside the grid rather than an element placed above it, so it scrolls with the grid, sits in the region a screen reader announces, and is kept by image capture and print. |
| showHeader | boolean | true | Draw the column headings at all. false removes the row, and removes it from the accessibility tree rather than only from view. Distinct from showColumnFunctions, which keeps the headings and drops only their sort, filter and menu controls. |
| overscan | number | 4 | Rows rendered beyond the viewport. |
| autoHeight | boolean | 'visible' | , | Size rows to their content: cells wrap instead of ellipsising, and each row takes the height its tallest cell needs. Only rendered rows are measured either way, the difference is that true stops measuring above 10,000 rows and returns to fixed heights, while 'visible' keeps measuring at any size and accepts a scrollbar that shifts as rows are measured on the way past. |
| columnVirtualisationAbove | number | 30 | Column count above which columns virtualise too. |
| state | GridState | , | Restore a saved view at construction. |
Performance
| Property | Type | Default | Description |
|---|---|---|---|
| useWorker | boolean | true | Compute column distributions off the main thread. Sorting, filtering and grouping run on the main thread. |
| workerThreshold | number | 50000 | Row count above which a distribution is sent to the Worker. |
| workerUrl | string | , | External worker file, for a CSP that forbids blob:. Settled when the Worker is built; changing it rebuilds one. |
| sharedMemory | boolean | false | Pass columns to the worker in a SharedArrayBuffer instead of copying them, where the page is cross-origin isolated. Retains a shared copy of each column that crosses. |
Chrome dom
| Property | Type | Description | |
|---|---|---|---|
| statusBar | boolean | { panels } | Composable panels along the bottom. Default set: rowCount, selectedCount, aggregation, comments, updates, progress. Each is silent when it has nothing to report. | |
| maximise | boolean | true | false removes the rail button and grid.maximise, for an application with its own full-screen mode. |
| toolPanel | boolean | object | Side dock. panels: columns, filters, views, quick, formatting, statistics. side: 'left' makes it the icon rail, which also turns on actions (undo, redo, pause, restore, maximise, then the export group: export, excel, clipboard, print: nine in all, and an array takes these names rather than the button labels) and icons. An explicit array replaces that list rather than extending it; a bare '-' in it renders a divider between groups. exportName names the CSV. | |
| timeZone | string | An IANA zone every date column formats and parses in, so a grid shows one zone whatever the viewer's machine says. Individual columns may override it. | |
| formulaFunctions | object | Your own functions, added to the formula language by name. The built-in list is closed on purpose; this is the one way in, and a function you add is called exactly as a built-in is. | |
| formatting | object | Conditional formatting rules to seed, keyed by column id or '*'. The same shape grid.formatting.all() returns, so a saved view can be handed straight back. | |
| facets | boolean | object | Header histograms that double as a filter. collapsed, height, and per-column strategy and buckets. | |
| updates | object | How a live feed behaves: batching, the queue that holds while paused, and the highlight a changed cell flashes. | |
| comments | object | Threaded cell comments: storage, the current author, and whether the indicator shows on an unread thread. | |
| presence | object | Live cursors, selections and edit locks. Carries intent and never values; see grid.presence. | |
| environment | function | Extra fields for the diagnostics bundle: build number, tenant, region. Called when a bundle is taken, never on the render path. | |
| contextMenu | boolean | (p) => MenuItem[] | Right-click menu. The function form is (params, defaults) => items: see custom items. false suppresses it: what a read-only grid wants, since the default menu offers Paste, Clear and Fill down. | |
| columnMenu | boolean | (p) => MenuItem[] | The header's 3-dot menu, and a right-click on a column heading. The function form is (params, defaults) => items, with params carrying colId, column and grid: see custom items. false suppresses it. | |
| shortcuts | boolean | true | The ? keyboard shortcut overlay. false suppresses it, for a host that wants ? for itself. See Keyboard. |
| rowReorder | boolean | { column } | , | Let a user reorder rows by dragging a handle or with Alt+Shift+arrows. The handle goes in the first visible column unless column names another. Refused, with a reason announced, while a sort, filter or grouping is active. See Row reorder. |
| rowTransfer | boolean | { send, receive, mode, group } | , | Let rows be dragged between grids. Off by default. send and receive are both on when present, so one-way is { receive: false } or { send: false }. mode: 'copy' leaves the row behind; group restricts which grids may exchange. See Moving rows between grids. |
| alignedGrids | Grid[] | , | Other grids to stay column-aligned with. Widths, order, visibility, pinning and horizontal scroll are shared; sort, filters, selection and rows stay independent. Declare it on the grid created last. See Aligned grids. |
| stickyGroupHeaders | boolean | number | { depth } | true | Keep the enclosing group headings pinned above the viewport while scrolling inside a group. Stacks at most two by default; each costs a row of viewport. See Sticky group headings. |
| gridLines | boolean | 'both' | 'horizontal' | 'vertical' | 'none' | 'horizontal' | Which rules are drawn between cells. Horizontal is what the grid has always drawn; vertical rules are additive. 'rows' and 'columns' are accepted aliases. Only the rules between data are affected, the header underline and pinned seams are structure. |
| cornerRadius | boolean | number | string | , | Round the grid's outer corners. true adopts the theme's radius, a number is pixels, a string is used as written. |
| columnTagFilter | boolean | { multiple, label } | , | A bar above the headings for showing only the columns carrying a chosen tag. Draws nothing unless some column has tags. See Column tags. |
| rowTemplate | string | { template, cardsPerRow, maxCardWidth, gap, className, role, itemRole } | , | Draw each row with a template instead of dividing it into columns, a card list, a feed, a search-result list. Compiles once; binds with {{data.field}}. cardsPerRow or maxCardWidth puts several on a line. The pipeline underneath is unchanged. See Cards, lists and feeds. |
| responsive | { maxWidth, template, rowHeight } | , | Collapse to cards when the container is at or below maxWidth (640 by default), and return to a table above it. Sorting, filtering and export keep working. Emits presentation:changed. See Cards, lists and feeds. |
| rowForm | boolean | { mode, load, fields, title, width, trigger, timeout, container } | , | Open a row for editing on a form. mode: 'drawer' (default) or 'dialog'; without load the fields are the grid's own columns. A field entry is { field, label, editor, type, props, lookup }: any editor, including your own. Takes double-click on the row unless trigger: false. A load that has not answered within timeout milliseconds (2000; false waits indefinitely) is reported as a failure with a retry. container builds the form in an element of your own instead of over the grid. See Editing a row on a form. |
| showColumnFunctions | boolean | true | false leaves each heading as its label, with no sort, filter or menu control. Those remain reachable through the API, the keyboard and the tool panel. |
| significantFigures | number | , | On a unit column, render to this many significant figures rather than a fixed number of decimals, so precision is the same on every rung of the ladder. Rounding is applied before the unit is chosen. Set inside the unit configuration a data type is built from. See Units. |
| typeOptions | object | , | Per-column options a data type reads. ratio and percentRate use { weight } to name the column their average is weighted by. See Aggregate safety. |
| highlightOnChange | boolean | string | object | Flash a cell when its value changes. { colour, duration }; duration: 0 stays until cleared. | |
| rowClass | string | string[] | (p) => … | A class, or classes, for every row. Re-evaluated on each repaint. | |
| rowStyle | CellStyle | (p) => CellStyle | Inline styles for every row. Camel-case or hyphenated property names. | |
| views | object | saved, allowSave, storage. See grid.views. | |
| permissions | string | object | fn | Per-column access. See grid.permissions. | |
| diff | object | { snapshot } turns on audit mode. | |
| historyBar | boolean | object | A standalone undo/redo toolbar with a timeline. | |
| ai | object | { ask } mounts the prompt bar. Your ask receives { prompt, schema, schemaText, message, context } and returns the model's reply. | |
| dataTypes | object | Custom types by name. createRadixType and createUnitType are exported for building them. | |
| editBar | boolean | A spreadsheet-style input above the header. When on, it hosts the column's real editor and inline editing is suppressed. | |
| pagination | boolean | object | Renders the pager control: page size, a summary, first/previous/next/last, and a page number you can type into and press Enter to jump. |
Column definition
Everything is optional. A column with only field infers its type from sampled data and takes every default from there.
| Property | Type | Description | |
|---|---|---|---|
| id | string | Defaults to field. Required when there is no field. | |
| field | string | Dotted paths supported: 'site.address.postcode'. | |
| title | string | Header text. Defaults to a humanised field. | |
| type | TypeName | false | A data type bundles format, parse, compare, storage, editor, filter, renderer and Excel behaviour. false disables inference. 'image' treats the value as a URL and draws it: see image columns. | |
| preset | string | string[] | Named bundles from columnPresets. | |
| tags | string | string[] | , | Labels grouping columns together, used by the column tag bar. A bare string is accepted for one tag. |
| format | FormatSpec | string | Shorthand strings like 'percent:1' or 'date:dd MMM yyyy'. | |
| lookup | LookupSpec | Id-to-label mapping. Nested children are flattened, so a tree-shaped list resolves labels everywhere. | |
| value | ColumnValueSpec | Computed values and the value lifecycle. | |
| cell | ColumnCellSpec | string | A bare string is a renderer name. | |
| edit | ColumnEditSpec | boolean | string | A bare string is an editor name. | |
| sort | ColumnSortSpec | boolean | ||
| filter | ColumnFilterSpec | boolean | FilterName | ||
| group | object | boolean | { enabled, index, explode }. | |
| pivot | object | boolean | { enabled, index }. | |
| total | TotalName | TotalFn | One property drives the group row, the tree node, the pivot cell and the grand total. | |
| layout | ColumnLayoutSpec | number | A bare number is the width. | |
| header | ColumnHeaderSpec | string | ||
| export | ColumnExportSpec | { lookup: 'label' | 'value' | 'columns', csv, excel }. | |
| allowGroup / allowPivot / allowTotal | boolean | Whether the tool panel offers the column for that zone. | |
| nullable | boolean | Affects storage choice and null ordering. |
Column sub-specs
value
| Key | Type | Description |
|---|---|---|
| compute | (deps, ctx) => unknown | Derived value. Receives only its declared dependencies. |
| deps | string[] | '*' | Declared dependencies. Cycles are caught at compile time, not at render. |
| pure | boolean | Allows caching. A DEV-mode proxy flags impure computes that read outside their deps. |
| format | (p) => string | Overrides the type's formatter. |
| parse | (p) => unknown | Editor output to value. Always called, whatever the editor emitted. |
| apply | (p) => boolean | Writes the value back into the row object. |
| key | (p) => string | Group key override. |
| compare | Comparator | Overrides the type's comparator. |
| quickFilterText | (p) => string | What the quick filter matches against. |
cell
| Key | Type | Description |
|---|---|---|
| render | RendererName | RenderFn | Ctor | Renderer name or component. The built-in names are listed under built-in renderers. |
| props | object | Passed to the renderer. |
| decoration | DecorationName | spec | pill, bar, fill, dot, edge. |
| variant | VariantSpec | Maps a value to a semantic token: { map }, or { when: [...], default }. |
| template | string | Escaped unless allowUnsafeTemplates is set. |
| class | string | string[] | (p) => … | Classes for this column's cells. |
| classWhen | { [class]: (p) => boolean } | A class per predicate, re-evaluated as values change. |
| style / css | CellStyle | (p) => CellStyle | Inline styles, static or computed. |
| tooltip | string | (p) => string | |
| align / wrap / autoHeight | , | Presentation flags. |
| spanColumns / spanRows | (p) => number | Spanned cells render in their own layer so row recycling cannot clip them. |
Custom CSS, by scope. Cells: cell.class,
cell.classWhen, cell.style and cell.css, all of which
may be functions of the cell. Columns: the same four, declared on the column, so they
apply to every cell in it; the header takes header.class. Rows:
rowClass and rowStyle on the grid.
All of them are re-evaluated on every repaint and remove what they added last time first. That is not caution: rows and cells come from pools, so an element that carried a class for one row will later carry a different row, and a class written once and left alone smears down the grid as the user scrolls.
edit, sort, filter, layout, header
| Spec | Keys |
|---|---|
| edit | enabled (boolean or predicate), editor, props, popup, validate |
| sort | enabled, direction, order, nullsFirst |
| filter | enabled, type, props |
| layout | width, min, max, flex, pin, hidden, resizable, movable, lockVisible, lockPosition. A pin of 'start' or 'end' holds the viewport edge while there is something to scroll; where the columns do not fill the grid, spare width falls beyond the last column rather than in front of it. |
| header | template, render, props, class, tooltip, align |
Grid methods
Top-level members. Everything else hangs off a namespace.
| Member | Returns | Description |
|---|---|---|
| getVersion() | string | The version this grid came from, e.g. '1.7.1'. Also on the module as getVersion(), for when you have no grid to hand. |
| get(key) | unknown | Read any configuration key. |
| set(key, value) | void | Write one key. Every key is live; nothing needs a rebuild. |
| setAll(values) | void | Write several in one pass. Emits one config:changed for the batch, not one per key. |
| config() | GridConfig | The whole live configuration as a shallow copy. Pairs with setAll for a read-modify-write round trip. Nested objects are shared by reference, so treat it as read-only. |
| setPinnedRows(rows, opts?) | void | Pin rows outside the scrolling body. opts.edge is 'top' (the default) or 'bottom'. Pass a new array rather than mutating the previous one: array identity is the change signal. See Pinned rows. |
| getPinnedRows(opts?) | object[] | The objects pinned at one edge, as a copy. |
| on(event, handler) | () => void | Returns its own unsubscribe. '*' subscribes to everything. |
| once(event, handler) | () => void | |
| off(event, handler) | void | |
| emit(event, payload) | void | Emit on the grid's bus, for custom components. |
| attachRenderer(renderer) | void | Bind a renderer to a headless grid. |
| destroy() | void | Release listeners, workers and pooled buffers. |
| element | HTMLElement | null | The rendered root; null when headless. |
| ready | boolean | |
| destroyed | boolean |
The reference, by namespace
Each area of the API is its own page, so you can link to the one that documents the method in front of you.
-
Rows, columns and data sources
grid.rows and the transaction API, grid.columns, the source modes, and the live-update stats.
-
Filtering, sorting and quick filter
grid.filters and the condition tree, grid.sort, facets, quick filter modes, and the filter grammar.
-
Editing, selection and history
grid.edit and validation, grid.selection and ranges, grid.history, column permissions, and your own menu items.
-
Renderers, formatting and charts
The built-in renderers and editors, grid.formatting and rules, in-cell charts, highlighting, and styling with CSS custom properties.
-
Charts, statistics and units
The charts module and createChart, grid.statistics and shadow columns, process capability, and unit systems of your own.
-
Export, state and saved views
grid.export to Excel and CSV, grid.state, grid.views, pagination and scroll.
-
Presence, comments and redaction
grid.presence, grid.comments, grid.redaction, and grid.diff.
-
Presentation, timeline and maximise
grid.presentation, grid.timeline, grid.maximise, and grid.overlay.
-
Adapters, the web component, htmx and events
The framework adapters, the web component, declarative init, the dhtmlx compatibility wrapper, htmx integration, and every event the grid emits.
-
The model layer, diagnostics and licence
grid.ai and the intent layer, grid.diagnostics, formulas, and grid.licence.
-
Accessibility
The keyboard map, the ARIA the grid writes, and the conformance notes.
-
Type reference
Every interface the library declares, with the type of each member, generated from the declarations so it always matches the release.