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 registrationGridElement.registerAdapter(new GridAdapter());Declarative usage with DataGrid:
Section titled “Declarative usage with DataGrid:”<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>Methods
Section titled “Methods”setTypeDefaults()
Section titled “setTypeDefaults()”Sets the type defaults map for this adapter. Called by DataGrid when it receives type defaults from context.
setTypeDefaults(defaults: TypeDefaultsMap | null): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
defaults | TypeDefaultsMap | unknown |
processConfig()
Section titled “processConfig()”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>Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
config | GridConfig<TRow> |
canHandle()
Section titled “canHandle()”Determines if this adapter can handle the given element. Checks if a renderer or editor is registered for this element.
canHandle(element: HTMLElement): booleanParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
element | HTMLElement |
createRenderer()
Section titled “createRenderer()”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> | undefinedParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
element | HTMLElement |
createEditor()
Section titled “createEditor()”Creates an editor spec that renders a React component with commit/cancel callbacks passed as props.
createEditor(element: HTMLElement): ColumnEditorSpec<TRow, TValue>Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
element | HTMLElement |
createDetailRenderer()
Section titled “createDetailRenderer()”Creates a detail renderer function for MasterDetailPlugin. Renders React components for expandable detail rows.
createDetailRenderer(gridElement: HTMLElement): (row: TRow, rowIndex: number) => HTMLElement | undefinedParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
gridElement | HTMLElement |
parseDetailElement()
Section titled “parseDetailElement()”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 | undefinedParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
detailElement | Element |
createResponsiveCardRenderer()
Section titled “createResponsiveCardRenderer()”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 | undefinedParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
gridElement | HTMLElement |
createToolPanelRenderer()
Section titled “createToolPanelRenderer()”Creates a tool panel renderer from a light DOM element. Renders React components into tool panel containers.
createToolPanelRenderer(element: HTMLElement): (container: HTMLElement) => void | () => void | undefinedParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
element | HTMLElement |
getTypeDefault()
Section titled “getTypeDefault()”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> | undefinedParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
type | string |
destroy()
Section titled “destroy()”Clean up all mounted React roots. Call this when the grid is unmounted.
destroy(): voidreleaseCell()
Section titled “releaseCell()”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): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
cellEl | HTMLElement |
unmount()
Section titled “unmount()”Unmount a specific container (called when cell is recycled).
unmount(container: HTMLElement): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
container | HTMLElement |