Types
Key TypeScript types and interfaces used throughout the ZenGrid API.
ZenGrid is written in TypeScript and exports all its types for use in your application.
Column Types
ColumnDef
Defines the configuration for a column.
interface ColumnDef { id?: string; field: string; header: string; width?: number; renderer?: string | CellRenderer; sortable?: boolean; editable?: boolean; editor?: string | CellEditor; editorOptions?: Record<string, any>; filterable?: boolean; resizable?: boolean; reorderable?: boolean; minWidth?: number; maxWidth?: number; overflow?: 'ellipsis' | 'clip' | 'wrap'; autoHeight?: boolean;}Properties:
id?: string- Unique column identifier (defaults to field name)field: string- Field name in data objectheader: string- Header textwidth?: number- Column width in pixelsrenderer?: string | CellRenderer- Custom cell renderersortable?: boolean- Enable sorting (default:true)editable?: boolean- Enable editing (default:false)editor?: string | CellEditor- Custom cell editoreditorOptions?: Record<string, any>- Editor configurationfilterable?: boolean- Enable filtering (default:true)resizable?: boolean- Enable resizing (default:true)reorderable?: boolean- Enable reordering (default:true)minWidth?: number- Minimum column widthmaxWidth?: number- Maximum column widthoverflow?: 'ellipsis' | 'clip' | 'wrap'- Cell overflow behaviorautoHeight?: boolean- Auto-calculate row height based on content
const columns: ColumnDef[] = [ { field: 'name', header: 'Full Name', width: 200, sortable: true, editable: true }, { field: 'email', header: 'Email Address', width: 250, renderer: 'link' }];Cell Types
CellRef
Reference to a specific cell by row and column index.
interface CellRef { row: number; col: number;}const cell: CellRef = { row: 5, col: 2 };grid.scrollToCell(cell.row, cell.col);CellRange
Defines a rectangular range of cells.
interface CellRange { startRow: number; startCol: number; endRow: number; endCol: number;}const range: CellRange = { startRow: 0, startCol: 0, endRow: 10, endCol: 5};CellPosition
Describes the visual position of a cell in the grid.
interface CellPosition { x: number; y: number; width: number; height: number;}Properties:
x: number- Left offset in pixelsy: number- Top offset in pixelswidth: number- Cell width in pixelsheight: number- Cell height in pixels
Viewport Types
VisibleRange
Range of currently visible cells.
interface VisibleRange { startRow: number; endRow: number; startCol: number; endCol: number;}const visibleRange = grid.getVisibleRange();console.log('Visible rows:', visibleRange.startRow, 'to', visibleRange.endRow);ScrollPosition
Current scroll position of the grid.
interface ScrollPosition { top: number; left: number;}const { top, left } = grid.getScrollPosition();Sort Types
SortState
Describes the sort state for a column.
interface SortState { column: number; direction: 'asc' | 'desc' | null; sortIndex?: number;}Properties:
column: number- Column indexdirection: 'asc' | 'desc' | null- Sort directionsortIndex?: number- Sort priority for multi-column sorting (0 is highest priority)
const sortState: SortState[] = [ { column: 0, direction: 'asc', sortIndex: 0 }, { column: 2, direction: 'desc', sortIndex: 1 }];grid.setSortState(sortState);SortDirection
Sort direction type.
type SortDirection = 'asc' | 'desc' | null;'asc'- Ascending order'desc'- Descending ordernull- No sort
Filter Types
FilterModel
Describes the filter state for a column.
interface FilterModel { column: number; conditions: FilterCondition[]; logic?: 'AND' | 'OR';}Properties:
column: number- Column indexconditions: FilterCondition[]- Array of filter conditionslogic?: 'AND' | 'OR'- Logical operator for multiple conditions (default:'AND')
const filterModel: FilterModel = { column: 1, conditions: [ { operator: 'greaterThan', value: 10 }, { operator: 'lessThan', value: 100 } ], logic: 'AND'};FilterCondition
Single filter condition.
interface FilterCondition { operator: FilterOperator; value?: any;}Properties:
operator: FilterOperator- Comparison operatorvalue?: any- Comparison value (not required for operators likeisEmpty)
FilterOperator
Available filter operators.
type FilterOperator = | 'equals' | 'notEquals' | 'contains' | 'notContains' | 'startsWith' | 'endsWith' | 'isEmpty' | 'isNotEmpty' | 'greaterThan' | 'greaterThanOrEqual' | 'lessThan' | 'lessThanOrEqual' | 'inRange' | 'between' | 'isNull' | 'isNotNull';Operators:
equals- Value equalsnotEquals- Value does not equalcontains- Text contains substringnotContains- Text does not contain substringstartsWith- Text starts withendsWith- Text ends withisEmpty- Value is empty stringisNotEmpty- Value is not empty stringgreaterThan- Numeric greater thangreaterThanOrEqual- Numeric greater than or equallessThan- Numeric less thanlessThanOrEqual- Numeric less than or equalinRange- Value in specified rangebetween- Alias forinRangeisNull- Value is null/undefinedisNotNull- Value is not null/undefined
FilterQuery
SQL-like input format for parsing filter state.
interface FilterQuery { sql: string; params?: any[];}Properties:
sql: string- SQL-like WHERE expression provided by the callerparams?: any[]- Parameterized values used during parsing
const query: FilterQuery = { sql: 'age > ? AND age < ?', params: [10, 100]};FilterExpression
Complete filter expression with a canonical AST plus compatibility projections.
interface FilterExpression { ast?: FilterAst | null; type: 'sql' | 'model'; sql?: string; boundSql?: string; params?: any[]; models?: FilterModel[]; quickFilter?: FilterQuickState; fieldState?: FieldFilterState | null; filterExport?: FilterExportResult | null;}Properties:
ast?: FilterAst | null- Canonical typed filter tree used by coretype: 'sql' | 'model'- Original input typesql?: string- Original SQL-like expression, when providedboundSql?: string- SQL with positional placeholdersparams?: any[]- Parameterized valuesmodels?: FilterModel[]- Column-model projection when representablequickFilter?: FilterQuickState- Quick filter statefieldState?: FieldFilterState | null- Field-oriented backend projectionfilterExport?: FilterExportResult | null- Prebuilt REST / GraphQL / SQL exports
filter.ast is the canonical filter contract. models, fieldState, and filterExport are derived projections that may be partial when a structured filter cannot be expressed in an older format.
FilterAst
Structured filter tree used by core state, frontend execution, and backend requests.
interface FilterAst { version: 1; root: FilterAstGroupNode | null;}Properties:
version: 1- Current AST schema versionroot: FilterAstGroupNode | null- Root group node, ornullwhen no structured filter is active
FilterAstTarget
Shared target reference for AST predicates and search nodes.
type FilterAstTarget = | { field: string; column?: number; columnId?: string } | { field?: string; column: number; columnId?: string } | { field?: string; column?: number; columnId: string };Notes:
- At least one of
field,column, orcolumnIdmust be present fieldis the preferred public identifiercolumnremains available for index-based compatibility
QueryPaginationState
Pagination slice embedded in backend query requests.
interface QueryPaginationState { page: number; pageSize: number; offset: number; cursor?: string | null;}QueryState
Canonical backend query envelope used by onDataRequest.
interface QueryState { version: 1; filter?: FilterAst | null; sort?: SortDescriptor[] | null; pagination?: QueryPaginationState | null;}Notes:
- Query slices may be omitted when inactive
- Slices may also be present with
nullvalues when a caller wants to be explicit - In
dataMode: 'auto', ZenGrid typically only populates the pagination/range slice because sort and filter still execute in the browser
Pagination Types
PaginationConfig
Pagination configuration options.
interface PaginationConfig { enabled: boolean; pageSize: number; template: string; position: 'top' | 'bottom' | 'both'; pageSizes: number[];}Properties:
enabled: boolean- Enable paginationpageSize: number- Rows per pagetemplate: string- Display template (e.g.,'Page {current} of {total}')position: 'top' | 'bottom' | 'both'- Pagination controls positionpageSizes: number[]- Available page size options
PaginationState
Current pagination state.
interface PaginationState { currentPage: number; pageSize: number; totalRows: number; totalPages: number; startRow: number; endRow: number;}Properties:
currentPage: number- Current page (1-based)pageSize: number- Rows per pagetotalRows: number- Total number of rowstotalPages: number- Total number of pagesstartRow: number- First row index on current pageendRow: number- Last row index on current page
State Types
GridStateSnapshot
Complete snapshot of grid state for save/restore.
interface GridStateSnapshot { columns: ColumnStateSnapshot[]; sort: SortState[]; filter: FilterModel[]; pagination?: PaginationState; scroll?: ScrollPosition; selection?: CellRange[];}Properties:
columns: ColumnStateSnapshot[]- Column statessort: SortState[]- Sort statefilter: FilterModel[]- Filter statepagination?: PaginationState- Pagination statescroll?: ScrollPosition- Scroll positionselection?: CellRange[]- Selection ranges
// Save stateconst snapshot = grid.getStateSnapshot();localStorage.setItem('gridState', JSON.stringify(snapshot));
// Restore stateconst saved = JSON.parse(localStorage.getItem('gridState'));grid.applyStateSnapshot(saved);ColumnStateSnapshot
State snapshot for a single column.
interface ColumnStateSnapshot { colId: string; width?: number; visible?: boolean; pinned?: 'left' | 'right' | null; sort?: SortState; filter?: FilterModel; order?: number;}Properties:
colId: string- Column identifierwidth?: number- Column widthvisible?: boolean- Visibility statepinned?: 'left' | 'right' | null- Pin statesort?: SortState- Sort statefilter?: FilterModel- Filter stateorder?: number- Display order
Export Types
GridExportOptions
Options for exporting grid data.
interface GridExportOptions { rows: 'all' | 'visible' | 'selected'; columns: 'all' | 'visible'; includeHeaders: boolean;}Properties:
rows: 'all' | 'visible' | 'selected'- Which rows to exportcolumns: 'all' | 'visible'- Which columns to exportincludeHeaders: boolean- Include column headers
const csv = grid.exportCSV({ rows: 'visible', columns: 'all', includeHeaders: true});Renderer Types
CellRenderer
Interface for custom cell renderers.
interface CellRenderer { render(params: RenderParams): HTMLElement; update?(params: RenderParams): void; destroy?(element: HTMLElement): void; getCellClass?(params: RenderParams): string;}Methods:
render(params): HTMLElement- Create and return the cell elementupdate?(params): void- Update existing cell element (optional)destroy?(element): void- Clean up when cell is destroyed (optional)getCellClass?(params): string- Return CSS class names for the cell (optional)
The update method is optional but recommended for performance. If not provided, the cell will be re-rendered on updates.
RenderParams
Parameters passed to cell renderers.
interface RenderParams { cell: CellRef; position: CellPosition; value: any; column?: ColumnDef; rowData?: any; isSelected: boolean; isActive: boolean; isEditing: boolean;}Properties:
cell: CellRef- Cell coordinatesposition: CellPosition- Visual positionvalue: any- Cell valuecolumn?: ColumnDef- Column definitionrowData?: any- Full row data objectisSelected: boolean- Selection stateisActive: boolean- Active (focused) stateisEditing: boolean- Editing state
const customRenderer: CellRenderer = { render(params) { const div = document.createElement('div'); div.textContent = params.value; if (params.isSelected) { div.classList.add('selected'); } return div; }, update(params) { const div = params.element; div.textContent = params.value; }};Editor Types
CellEditor
Interface for custom cell editors.
interface CellEditor { init(params: EditorParams): HTMLElement; getValue(): any; focus(): void; destroy(): void; isValid?(): boolean; onKeyDown?(event: KeyboardEvent): void;}Methods:
init(params): HTMLElement- Create and return the editor elementgetValue(): any- Get the current editor valuefocus(): void- Focus the editordestroy(): void- Clean up when editor is closedisValid?(): boolean- Validate current value (optional)onKeyDown?(event): void- Handle keyboard events (optional)
EditorParams
Parameters passed to cell editors.
interface EditorParams { cell: CellRef; column?: ColumnDef; rowData?: any; onComplete?: (value: any) => void; onChange?: (value: any) => void; options?: Record<string, any>; registerPopup?: (element: HTMLElement) => void; unregisterPopup?: (element: HTMLElement) => void;}Properties:
cell: CellRef- Cell being editedcolumn?: ColumnDef- Column definitionrowData?: any- Full row dataonComplete?: (value) => void- Callback when editing completesonChange?: (value) => void- Callback when value changesoptions?: Record<string, any>- Editor-specific optionsregisterPopup?: (element) => void- Register popup element (for dropdowns)unregisterPopup?: (element) => void- Unregister popup element
const customEditor: CellEditor = { init(params) { const input = document.createElement('input'); input.type = 'text'; input.value = params.value || ''; input.addEventListener('change', () => { params.onChange?.(input.value); }); return input; }, getValue() { return this.input.value; }, focus() { this.input.focus(); }, destroy() { // Cleanup }};Header Renderer Types
HeaderRenderer
Interface for custom header renderers.
interface HeaderRenderer { render(params: HeaderRenderParams): HTMLElement; update?(params: HeaderRenderParams): void; destroy?(element: HTMLElement): void; getHeaderClass?(params: HeaderRenderParams): string;}Methods:
render(params): HTMLElement- Create and return the header elementupdate?(params): void- Update existing header element (optional)destroy?(element): void- Clean up when header is destroyed (optional)getHeaderClass?(params): string- Return CSS class names (optional)
HeaderRenderParams
Parameters passed to header renderers.
interface HeaderRenderParams { columnIndex: number; column?: ColumnDef; config: any; width: number; height: number; isHovered?: boolean; isFocused?: boolean; isResizing?: boolean; emit?: (event: string, data?: any) => void;}Properties:
columnIndex: number- Column indexcolumn?: ColumnDef- Column definitionconfig: any- Header configurationwidth: number- Header widthheight: number- Header heightisHovered?: boolean- Hover stateisFocused?: boolean- Focus stateisResizing?: boolean- Resize stateemit?: (event, data) => void- Event emitter
Plugin Types
GridPlugin
Interface for grid plugins.
interface GridPlugin { name: string; phase: number; dependencies?: string[]; setup(store: GridStore, api: GridApiInterface, context: GridPluginSetupContext): PluginDisposable | void; dispose?(): void;}Properties:
name: string- Unique plugin namephase: number- Initialization phasedependencies?: string[]- Names of required pluginssetup(store, api, context)- Setup function called during initializationdispose?(): void- Cleanup function (optional)
GridPluginSetupContext
Live runtime option access for plugins.
interface GridPluginSetupContext { options: GridOptions; getOptions(): GridOptions; getOptionsSnapshot(): GridOptions; subscribeOptions(listener: GridOptionsListener): () => void;}const customPlugin: GridPlugin = { name: 'custom-plugin', phase: 60, setup(store, api, context) { const unsubscribeOptions = context.subscribeOptions((change) => { console.log('Updated option keys:', change.changedKeys); });
return { teardown: [unsubscribeOptions] }; }, dispose() { // Cleanup }};
grid.usePlugin(customPlugin);All types are exported from the @zengrid/core package and can be imported for use in your TypeScript code.
Type Imports
import type { Grid, GridOptions, ColumnDef, CellRef, CellRange, SortState, FilterModel, FilterOperator, CellRenderer, RenderParams, CellEditor, EditorParams, HeaderRenderer, HeaderRenderParams, GridPlugin} from '@zengrid/core';