SciGrid Class
The SciGrid class is the core entry point of the library. It manages the canvas lifecycle, renders the grid, and handles user interactions.
Constructor
new SciGrid(container: HTMLElement, provider: IDataGridProvider, config?: Partial<GridConfig>)Parameters
| Name | Type | Description |
|---|---|---|
container | HTMLElement | The DOM element where the grid will be rendered. It should have a defined height. |
provider | IDataGridProvider | The data source for the grid. See Provider API. |
config | Partial<GridConfig> | (Optional) Configuration options. |
Methods
destroy()
Destroys the grid instance, removing all event listeners and DOM elements (canvas) attached to the container.
grid.destroy(): voidupdateConfig(config)
Updates the grid configuration. Merges the provided options with the existing configuration. Triggers a re-render.
grid.updateConfig(config: Partial<GridConfig>): voidupdateProvider(provider)
Replaces the current data provider with a new one. Useful for completely swapping datasets.
grid.updateProvider(provider: IDataGridProvider): voidrenderNow()
Forces an immediate synchronous render of the grid. Usually, the grid renders automatically on interaction or requestAnimationFrame, but this can be used to force an update after external data changes.
grid.renderNow(): voidinvalidate()
Marks the grid as dirty and requests a render in the next animation frame. This is the preferred way to trigger updates after data changes.
grid.invalidate(): voidgetSelection()
Returns the current selection information.
grid.getSelection(): SelectionInfoeditCell(row, col, value)
Edits a cell value with validation and undo tracking. If a validator is configured for the column and the value fails validation, the edit is silently rejected.
grid.editCell(row: number, col: number, value: any): voidaddSort(col, order)
Adds or updates a sort on a column. Supports multi-column sorting.
grid.addSort(col: number, order: 'asc' | 'desc'): voidclearSort()
Removes all active sorts.
grid.clearSort(): voidaddFilter(filter)
Adds or updates a filter on a column.
grid.addFilter(filter: ColumnFilter): voidremoveFilter(col)
Removes the filter from a specific column.
grid.removeFilter(col: number): voidclearFilters()
Removes all active filters.
grid.clearFilters(): voidsetGroupBy(col, aggregations?)
Groups rows by a column, optionally with per-column aggregations.
grid.setGroupBy(col: number, aggregations?: Record<number, AggregationType>): voidclearGroupBy()
Removes row grouping.
grid.clearGroupBy(): voidtoggleGroup(groupValue)
Expands or collapses a group by its value.
grid.toggleGroup(groupValue: string): voidgetAggregation(col, type)
Computes an aggregation over visible (filtered) rows.
grid.getAggregation(col: number, type: AggregationType): GridDataValuerebuildDataView()
Rebuilds the internal data view (filter + sort + group). Call this after changing config.filters, config.sortState, or config.groupBy directly.
grid.rebuildDataView(): voidgetRealRow(virtualRow)
Maps a virtual (displayed) row index to the real row index in the data provider.
grid.getRealRow(virtualRow: number): numbergetVisibleRowCount()
Returns the number of visible rows after filtering.
grid.getVisibleRowCount(): number