Data grid / foldkit-mixins-data-grid
mixins-data-grid
Drawing 100,000 rows straight into HTML crashes the browser layout, and
building a virtualized table by hand still leaves you wiring WAI-ARIA grid
roles, aria-activedescendant focus across scrolled windows, sticky pinned
columns, resize handles, and inline cell editors.
foldkit-mixins-data-grid renders a foldkit-data-grid
model as an accessible, virtualized WAI-ARIA grid. Only the rows and columns
inside the scroll viewport reach the DOM, while logical row counts, keyboard
movement, selection, clipboard shortcuts, and styling Slots work out of the box.
See 100,000 virtualized rows rendered with it in the live data grid demo.
Install
pnpm add effect foldkit foldkit-data-grid foldkit-mixins foldkit-mixins-data-gridA first virtualized grid
This defines a two-column DataGrid, attaches the default GridStyle, and
renders the virtualized grid view:
import type { HtmlBuilder } from 'foldkit/html'
import { Columns, DataGrid, RowModel } from 'foldkit-data-grid'
import { Style } from 'foldkit-mixins'
import { DataGridView, GridStyle } from 'foldkit-mixins-data-grid'
interface Item { readonly id: string; readonly name: string }
const columns = Columns.define<Item>()({
id: { header: 'Id', value: item => item.id, pinned: 'start', width: 96 },
name: { header: 'Name', value: item => item.name, width: 240 },
})
const Grid = DataGrid.make({ id: 'items', columns })
const ItemsGrid = DataGridView<typeof Grid.Message.Type>().define(Grid).pipe(Style.attach(GridStyle))
const rows = RowModel.fromArray([{ id: 'a', name: 'Anchor' }, { id: 'b', name: 'Bolt' }], i => i.id)
const wrap = (message: typeof Grid.Message.Type) => message
const view = (state: typeof Grid.Model.Type, h: HtmlBuilder<typeof Grid.Message.Type>) =>
ItemsGrid({ state, rows, wrap, label: 'Items', rowHeight: 32, headerHeight: 36 }, h)Passing Grid.bundle.init(undefined).model to view renders a role="grid"
scroll container (aria-rowcount="3", aria-colcount="2") with a sticky Id
header and body rows sized to fit the viewport. Give root a height via Style
(such as height: '24rem') so the grid container scrolls.
DataGridView<Message>().define(Grid)creates a SlotView typed toGrid's row and column types so custom cell renderers and focused addresses are type-checked.stateis theDataGridModel holding the focused cell, viewport geometry, and column layout used to computeVirtualGrid.window.rowsis yourRowModelin display order; keep theRowModelreference stable between renders so the projection stays cached.wraplifts grid Messages into your application Message union when placed withfoldkit-bundle.- Per-row memoization skips redrawing unchanged rows when focus moves or
the grid scrolls, as long as
wrap,cell, andmarkskeep stable function identities across renders. GridStyleprovides the default styling in thecomponentslayer.
Where rows, grid state, and view markup live
| Fact | Owner |
|---|---|
| the rows, their order | your application |
| the focused cell, the scroll offsets and size | DataGrid, in your Model |
| which cells to draw, and their ARIA | this view, derived each render |
Your application owns the rows and places the DataGrid Bundle in its Model;
this view reads both and dispatches grid Messages through wrap.