Skip to content

GridAdapter

Framework adapter that enables React component integration with the grid’s light DOM configuration API.

The adapter is automatically registered when using the DataGrid component. For advanced use cases, you can manually register:

import { GridElement } from '@toolbox-web/grid';
import { GridAdapter } from '@toolbox-web/grid-react';
// One-time registration
GridElement.registerAdapter(new GridAdapter());
<DataGrid rows={data} gridConfig={config}>
<GridColumn field="status">
{(ctx) => <StatusBadge value={ctx.value} />}
</GridColumn>
<GridColumn field="name" editor={(ctx) => (
<NameEditor value={ctx.value} onCommit={ctx.commit} onCancel={ctx.cancel} />
)} />
</DataGrid>

Sets the type defaults map for this adapter. Called by DataGrid when it receives type defaults from context.

setTypeDefaults(defaults: TypeDefaultsMap | null): void
NameTypeDescription
defaultsTypeDefaultsMap | unknown

FrameworkAdapter.processConfig implementation. Called automatically by the grid’s set gridConfig setter. Converts React renderer/editor functions to DOM-returning functions.

processConfig(config: GridConfig<TRow>): GridConfig<TRow>
NameTypeDescription
configGridConfig<TRow>

Determines if this adapter can handle the given element. Checks if a renderer or editor is registered for this element.

canHandle(element: HTMLElement): boolean
NameTypeDescription
elementHTMLElement

Creates a view renderer function that renders a React component and returns its container DOM element.

Uses a cell cache to reuse React roots for performance - instead of creating new roots on each render, we reuse existing ones and just call root.render() with new data.

Returns undefined if no renderer is registered for this element, allowing the grid to use its default rendering.

createRenderer(element: HTMLElement): ColumnViewRenderer<TRow, TValue> | undefined
NameTypeDescription
elementHTMLElement

Creates an editor spec that renders a React component with commit/cancel callbacks passed as props.

createEditor(element: HTMLElement): ColumnEditorSpec<TRow, TValue>
NameTypeDescription
elementHTMLElement

Creates a detail renderer function for MasterDetailPlugin. Renders React components for expandable detail rows.

createDetailRenderer(gridElement: HTMLElement): (row: TRow, rowIndex: number) => HTMLElement | undefined
NameTypeDescription
gridElementHTMLElement

Framework adapter hook called by MasterDetailPlugin during attach(). Parses the <tbw-grid-detail> element and returns a React-based renderer.

parseDetailElement(detailElement: Element): (row: TRow, rowIndex: number) => string | HTMLElement | undefined
NameTypeDescription
detailElementElement

Creates a responsive card renderer function for ResponsivePlugin. Renders React components for card layout in responsive mode.

createResponsiveCardRenderer(gridElement: HTMLElement): (row: TRow, rowIndex: number) => HTMLElement | undefined
NameTypeDescription
gridElementHTMLElement

Creates a tool panel renderer from a light DOM element. Renders React components into tool panel containers.

createToolPanelRenderer(element: HTMLElement): (container: HTMLElement) => void | () => void | undefined
NameTypeDescription
elementHTMLElement

Gets type-level defaults from the type defaults map.

This enables application-wide type defaults configured via GridTypeProvider. The returned TypeDefault contains renderer/editor functions that render React components into the grid’s cells.

getTypeDefault(type: string): TypeDefault<TRow> | undefined
NameTypeDescription
typestring

Clean up all mounted React roots. Call this when the grid is unmounted.

destroy(): void

Called when a cell’s content is about to be wiped. Destroys editor React roots whose container is inside the cell. Also cleans up config-based editor roots (from processGridConfig/wrapReactEditor) that bypass the adapter’s tracking arrays.

releaseCell(cellEl: HTMLElement): void
NameTypeDescription
cellElHTMLElement

Unmount a specific container (called when cell is recycled).

unmount(container: HTMLElement): void
NameTypeDescription
containerHTMLElement

AI assistants: For complete API documentation, implementation guides, and code examples for this library, see https://raw.githubusercontent.com/OysteinAmundsen/toolbox/main/llms-full.txt