PublicGrid
Since v0.1.1
Public API interface for DataGrid component.
Property Getters vs Setters:
Property getters return the EFFECTIVE (resolved) value after merging all config sources. This is the “current situation” - what consumers and plugins need to know.
Property setters accept input values which are merged into the effective config. Multiple sources can contribute (gridConfig, columns prop, light DOM, individual props).
For example:
grid.fitModereturns the resolved fitMode (e.g., ‘stretch’ even if you set undefined)grid.columnsreturns the effective columns after merginggrid.gridConfigreturns the full effective config
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
gridConfig? | GridConfig<T, ColumnFieldKey<T>> | Full config object. Setter merges with other inputs per precedence rules. Getter returns the effective (resolved) config. |
columns? | ColumnConfig<T, ColumnFieldKey<T>>[] | Column definitions. Getter returns effective columns (after merging config, light DOM, inference). |
rows? | T[] | Current row data (after plugin processing like grouping, filtering). |
ready? | () => Promise<void> | Resolves once the component has finished initial work (layout, inference). |
forceLayout? | () => Promise<void> | Force a layout / measurement pass (e.g. after container resize). |
getConfig? | () => Promise<Readonly<GridConfig<T, ColumnFieldKey<T>>>> | Return effective resolved config (after inference & precedence). |
toggleGroup? | (key: string) => Promise<void> | Toggle expansion state of a group row by its generated key. |
registerStyles? | (id: string, css: string) => void | Register custom CSS styles to be injected into the grid. Use this to style custom cell renderers, editors, or detail panels. |
unregisterStyles? | (id: string) => void | Remove previously registered custom styles. |
getRegisteredStyles? | () => string[] | Get list of registered custom style IDs. |
columnState? | GridColumnState | Read the current column state. Property-style accessor that mirrors PublicGrid.getColumnState. To restore state, use PublicGrid.applyColumnState. |
sortModel? | { field: string; direction: desc | asc } | unknown | Get the current sort state. |
loading? | boolean | Whether the grid is currently in a loading state. When true, displays a loading overlay with spinner. |
focusedCell? | { rowIndex: number; colIndex: number; field: string } | unknown | The currently focused cell position, or null if no rows are loaded. |
Property Details
Section titled “Property Details”columnState
Section titled “columnState”const snapshot = grid.columnState;sortModel
Section titled “sortModel”Get the current sort state.
Returns null when no sort is active.
const sort = grid.sortModel;// { field: 'id', direction: 'desc' } | nullloading
Section titled “loading”Whether the grid is currently in a loading state. When true, displays a loading overlay with spinner.
Can also be set via the loading HTML attribute.
// Show loading overlaygrid.loading = true;const data = await fetchData();grid.rows = data;grid.loading = false;Methods
Section titled “Methods”insertRow()
Section titled “insertRow()”Insert a row at a visible index, bypassing the sort/filter pipeline. Auto-animates by default.
insertRow(index: number, row: T, animate: boolean): Promise<void>Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
index | number | |
row | T | |
animate | boolean |
removeRow()
Section titled “removeRow()”Remove a row at a visible index, bypassing the sort/filter pipeline. Auto-animates by default.
removeRow(index: number, animate: boolean): Promise<T | undefined>Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
index | number | |
animate | boolean |
applyTransaction()
Section titled “applyTransaction()”Apply a batch of add/update/remove mutations in a single render cycle.
applyTransaction(transaction: RowTransaction<T>, animate: boolean): Promise<TransactionResult<T>>Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
transaction | RowTransaction<T> | |
animate | boolean |
applyTransactionAsync()
Section titled “applyTransactionAsync()”Batch-friendly version — merges rapid calls within a single animation frame.
applyTransactionAsync(transaction: RowTransaction<T>): Promise<TransactionResult<T>>Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
transaction | RowTransaction<T> |
getPlugin()
Section titled “getPlugin()”Get a plugin instance by its class.
Prefer getPluginByName — it avoids importing the plugin class and returns the actual registered instance with full type narrowing.
getPlugin(PluginClass: (args: any[]) => P): P | undefinedParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
PluginClass | (args: any[]) => P |
Example
Section titled “Example”// Preferred: by nameconst selection = grid.getPluginByName('selection');
// Alternative: by classconst selection = grid.getPlugin(SelectionPlugin);if (selection) { selection.selectAll();}getPluginByName()
Section titled “getPluginByName()”Get a plugin instance by its name.
When a plugin augments the PluginNameMap interface, the return
type is narrowed automatically:
const editing = grid.getPluginByName('editing');editing?.beginBulkEdit(0); // ✅ typed as EditingPluginFor unknown names the return type falls back to GridPlugin | undefined.
getPluginByName(name: K): unknown | undefinedParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
name | K |
refreshShellHeader()
Section titled “refreshShellHeader()”Re-render the shell header (title, column groups, toolbar). Call this after dynamically adding/removing tool panels or toolbar buttons.
refreshShellHeader(): voidregisterToolPanel()
Section titled “registerToolPanel()”Register a custom tool panel in the sidebar.
registerToolPanel(panel: ToolPanelDefinition): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
panel | ToolPanelDefinition |
Example
Section titled “Example”grid.registerToolPanel({ id: 'analytics', title: 'Analytics', icon: '📊', render: (container) => { container.innerHTML = '<div>Charts here...</div>'; }});unregisterToolPanel()
Section titled “unregisterToolPanel()”Unregister a previously registered tool panel.
unregisterToolPanel(panelId: string): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
panelId | string |
openToolPanel()
Section titled “openToolPanel()”Open the tool panel sidebar.
openToolPanel(panelId: string): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
panelId | string | Optional ID of the section to expand on open. Takes precedence |
over shell.toolPanel.defaultOpen. Falls back to default behavior with a | ||
| warning if the ID is not registered. |
closeToolPanel()
Section titled “closeToolPanel()”Close the tool panel sidebar.
closeToolPanel(): voidtoggleToolPanel()
Section titled “toggleToolPanel()”Toggle the tool panel sidebar open or closed.
toggleToolPanel(): voidtoggleToolPanelSection()
Section titled “toggleToolPanelSection()”Toggle an accordion section expanded or collapsed within the tool panel.
toggleToolPanelSection(sectionId: string): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
sectionId | string | The ID of the section to toggle |
getColumnState()
Section titled “getColumnState()”Get the current column state including order, width, visibility, and sort. Use for persisting user preferences to localStorage or a backend.
getColumnState(): GridColumnStateExample
Section titled “Example”const state = grid.getColumnState();localStorage.setItem('gridState', JSON.stringify(state));applyColumnState()
Section titled “applyColumnState()”Apply a previously saved column state, restoring column order, widths, visibility, sort, and any plugin-contributed state. Can be called before or after grid initialization — pre-init calls are deferred and applied during setup.
applyColumnState(state: GridColumnState | undefined): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
state | GridColumnState | undefined |
Example
Section titled “Example”const saved = localStorage.getItem('gridState');if (saved) grid.applyColumnState(JSON.parse(saved));sort()
Section titled “sort()”Sort by a column, toggle a column’s sort direction, or clear sorting.
sort('id', 'desc')— apply sort with explicit directionsort('id')— toggle: none → asc → desc → nonesort(null)— clear sort, restore original row order
sort(field: string | null, direction: "desc" | "asc"): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
field | string | unknown | Column field to sort by, or null to clear |
direction | desc | asc | Explicit direction; omit to toggle |
Example
Section titled “Example”grid.sort('id', 'desc'); // sort descendinggrid.sort('price'); // toggle sort on pricegrid.sort(null); // clear sortsetRowLoading()
Section titled “setRowLoading()”Set loading state for a specific row. Displays a small spinner indicator on the row.
Use when persisting row data or performing row-level async operations.
setRowLoading(rowId: string, loading: boolean): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
rowId | string | The row’s unique identifier (from getRowId) |
loading | boolean | Whether the row is loading |
Example
Section titled “Example”// Show loading while saving rowgrid.setRowLoading('emp-123', true);await saveRow(row);grid.setRowLoading('emp-123', false);setCellLoading()
Section titled “setCellLoading()”Set loading state for a specific cell. Displays a small spinner indicator on the cell.
Use when performing cell-level async operations (e.g., validation, lookup).
setCellLoading(rowId: string, field: string, loading: boolean): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
rowId | string | The row’s unique identifier (from getRowId) |
field | string | The column field |
loading | boolean | Whether the cell is loading |
Example
Section titled “Example”// Show loading while validating cellgrid.setCellLoading('emp-123', 'email', true);const isValid = await validateEmail(email);grid.setCellLoading('emp-123', 'email', false);isRowLoading()
Section titled “isRowLoading()”Check if a row is currently in loading state.
isRowLoading(rowId: string): booleanParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
rowId | string | The row’s unique identifier |
isCellLoading()
Section titled “isCellLoading()”Check if a cell is currently in loading state.
isCellLoading(rowId: string, field: string): booleanParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
rowId | string | The row’s unique identifier |
field | string | The column field |
clearAllLoading()
Section titled “clearAllLoading()”Clear all row and cell loading states.
clearAllLoading(): voidregisterExternalFocusContainer()
Section titled “registerExternalFocusContainer()”Register an external DOM element as a logical focus container of this grid.
Focus moving into a registered container is treated as if it stayed inside
the grid: data-has-focus is preserved, click-outside commit is suppressed,
and the editing focus trap (when enabled) won’t reclaim focus.
Typical use case: overlay panels (datepickers, dropdowns, autocompletes)
that render at <body> level to escape grid overflow clipping.
registerExternalFocusContainer(el: Element): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
el | Element | The external element to register |
Example
Section titled “Example”const overlay = document.createElement('div');document.body.appendChild(overlay);
// Tell the grid this overlay is "part of" the gridgrid.registerExternalFocusContainer(overlay);
// Later, when overlay is removedgrid.unregisterExternalFocusContainer(overlay);unregisterExternalFocusContainer()
Section titled “unregisterExternalFocusContainer()”Unregister a previously registered external focus container.
unregisterExternalFocusContainer(el: Element): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
el | Element | The element to unregister |
containsFocus()
Section titled “containsFocus()”Check whether focus is logically inside this grid.
Returns true when document.activeElement (or the given node) is
inside the grid’s own DOM or inside any element registered via
registerExternalFocusContainer.
containsFocus(node: Node | null): booleanParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
node | Node | unknown | Optional node to test. Defaults to document.activeElement. |
Example
Section titled “Example”if (grid.containsFocus()) { console.log('Grid or one of its overlays has focus');}focusCell()
Section titled “focusCell()”Move focus to a specific cell.
focusCell(rowIndex: number, column: string | number): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
rowIndex | number | Row index (0-based, in the current processed row array) |
column | string | number | Column index (0-based into visible columns) or field name |
scrollToRow()
Section titled “scrollToRow()”Scroll to make a row visible by its index.
scrollToRow(rowIndex: number, options: ScrollToRowOptions): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
rowIndex | number | Row index (0-based, in the current processed row array) |
options | ScrollToRowOptions | Scroll alignment and behavior |
scrollToRowById()
Section titled “scrollToRowById()”Scroll to make a row visible by its unique ID.
scrollToRowById(rowId: string, options: ScrollToRowOptions): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
rowId | string | The row’s unique identifier (from getRowId) |
options | ScrollToRowOptions | Scroll alignment and behavior |