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

sh
pnpm add effect foldkit foldkit-data-grid foldkit-mixins foldkit-mixins-data-grid

A first virtualized grid

This defines a two-column DataGrid, attaches the default GridStyle, and renders the virtualized grid view:

ts
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 to Grid's row and column types so custom cell renderers and focused addresses are type-checked.
  • state is the DataGrid Model holding the focused cell, viewport geometry, and column layout used to compute VirtualGrid.window.
  • rows is your RowModel in display order; keep the RowModel reference stable between renders so the projection stays cached.
  • wrap lifts grid Messages into your application Message union when placed with foldkit-bundle.
  • Per-row memoization skips redrawing unchanged rows when focus moves or the grid scrolls, as long as wrap, cell, and marks keep stable function identities across renders.
  • GridStyle provides the default styling in the components layer.

Where rows, grid state, and view markup live

FactOwner
the rows, their orderyour application
the focused cell, the scroll offsets and sizeDataGrid, in your Model
which cells to draw, and their ARIAthis 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.