Skip to main content

Types reference

All types are exported from @dhx/react-spreadsheet or @dhtmlx/trial-react-spreadsheet.

import type { SheetData, CellData, SpreadsheetRef /* ... */ } from "@dhtmlx/trial-react-spreadsheet";

CellData

A single cell's declarative state. All properties are optional; omitted properties retain their current value during updates.

PropertyTypeDescription
valuestring | numberCell value: text, number, or formula string (prefixed with =).
cssstringCSS class name(s) referencing keys in the top-level styles map.
formatstringNumber format mask or alias (e.g. "currency", "#,##0.00").
lockedbooleanWhether the cell is locked (protected from editing).
validationstring | string[]Data validation dropdown options.

RowConfig

Row metadata. Only rows with non-default config need entries.

PropertyTypeDescription
heightnumberRow height in pixels.
hiddenbooleanWhether the row is hidden.

ColConfig

Column metadata. Only columns with non-default config need entries.

PropertyTypeDescription
widthnumberColumn width in pixels.
hiddenbooleanWhether the column is hidden.

MergedRange

Defines a merged cell range using 0-indexed row/column coordinates.

PropertyTypeDescription
from{ row: number; column: number }Top-left corner of the merge (0-indexed).
to{ row: number; column: number }Bottom-right corner of the merge (0-indexed).

Example:

// Merge A1:B2
const merge: MergedRange = {
from: { row: 0, column: 0 },
to: { row: 1, column: 1 },
};

FreezeConfig

Freeze pane configuration for a sheet.

PropertyTypeDescription
colnumberFreeze columns up to this 0-indexed column number. undefined = no column freeze.
rownumberFreeze rows up to this 0-indexed row number. undefined = no row freeze.

SheetFilter

Filter configuration for a column within a sheet.

PropertyTypeDescription
cellstringCell reference identifying the filtered column (e.g. "A1").
rulesIFilterRules[]Filter rules to apply. Empty array clears the filter.

SheetSort

Sort configuration for a column within a sheet.

PropertyTypeDescription
cellstringCell reference or range for the sort operation (e.g. "B1" or "A1:E8"). Use a range to sort multiple columns together while maintaining row integrity.
dir1 | -1Sort direction: 1 = ascending, -1 = descending.

SheetData

Complete declarative state for a single spreadsheet sheet.

PropertyTypeRequiredDescription
idIdYesUnique sheet identifier. Must be stable across renders.
namestringYesDisplay name shown on the sheet tab.
cellsRecord<string, CellData>YesCell data keyed by cell reference (e.g. "A1", "B2"). Only cells with non-default data need entries.
rowsRecord<number, RowConfig>NoRow configuration keyed by 0-indexed row number.
colsRecord<number, ColConfig>NoColumn configuration keyed by 0-indexed column number.
mergedMergedRange[]NoMerged cell ranges.
freezeFreezeConfigNoFrozen pane configuration.
filterSheetFilterNoColumn filter configuration. Set to undefined to clear.
sortSheetSortNoSort configuration.

Example:

const sheet: SheetData = {
id: "sheet1",
name: "Inventory",
cells: {
A1: { value: "Product", css: "bold" },
B1: { value: "Quantity", css: "bold" },
A2: { value: "Laptop" },
B2: { value: 42 },
},
cols: { 0: { width: 200 } },
freeze: { row: 1 },
};

SearchConfig

Controlled search state. Pass an object to trigger/update search, pass undefined to dismiss.

PropertyTypeRequiredDescription
querystringYesText to search for.
openbooleanNoWhether to open the built-in search UI. Default: false.
sheetIdIdNoRestrict search to a specific sheet by id.

SpreadsheetLocale

Localization configuration for UI labels and formula names.

PropertyTypeDescription
localeRecord<string, string>UI string overrides. Keys match the library's locale dictionary.
formulasRecord<string, [string, string?][]>Localized formula names grouped by category. Each entry is a tuple: [localizedName, optionalDescription?].

SpreadsheetTheme

type SpreadsheetTheme = "light" | "dark" | "contrast-light" | "contrast-dark" | string;

Built-in color themes. Also accepts custom theme name strings.

IExecuteConfig

Action execution configuration passed to onBeforeAction / onAfterAction. Shape varies by action type.

PropertyTypeDescription
rownumberTarget row index.
colnumberTarget column index.
targetunknownAction-specific target.
valunknownNew value.
prevunknownPrevious value.
actionActions | stringAction identifier.
groupActionActions | stringParent group action identifier.
cellstringCell reference (e.g. "A1").
pageIdIdTarget sheet id.
pageNamestringTarget sheet name.
[key: string]unknownAdditional action-specific properties.

SpreadsheetRef

Imperative handle exposed via React.forwardRef. Provides direct access to the underlying DHTMLX Spreadsheet instance for operations that don't map to declarative props.

PropertyTypeDescription
instanceISpreadsheet | nullThe underlying widget instance. null before initialization and after unmount.

Example:

const ref = useRef<SpreadsheetRef>(null);

// Serialize data
const data = ref.current?.instance?.serialize();

// Programmatic selection
ref.current?.instance?.selection.setSelectedCell("A1:C5");

// Undo/redo
ref.current?.instance?.undo();
ref.current?.instance?.redo();

Actions enum

Known spreadsheet action identifiers. Used in onBeforeAction / onAfterAction for type-safe action matching. The | string union on handler params allows forward-compatibility with future actions.

ValueDescription
setCellStyleApply CSS style to cell(s).
setCellValueSet cell value.
setCellFormatSet number format on cell(s).
removeCellStylesRemove CSS styles from cell(s).
lockCellLock or unlock cell(s).
deleteRowDelete row(s).
addRowInsert row(s).
deleteColumnDelete column(s).
addColumnInsert column(s).
groupActionBatch action (multiple sub-actions).
groupRowActionBatch row action.
groupColActionBatch column action.
addSheetAdd a new sheet.
deleteSheetDelete a sheet.
renameSheetRename a sheet.
clearSheetClear all data in a sheet.
clearClear selected cells.
resizeColResize column width.
resizeRowResize row height.
setValidationSet data validation on cell(s).
sortCellsSort cells.
insertLinkInsert a hyperlink.
fitColumnAuto-fit column width to content.
filterApply or change column filter.
mergeMerge cells.
unmergeUnmerge cells.
toggleFreezeToggle freeze panes.
toggleVisibilityToggle row/column visibility.

Handler type aliases

Convenience aliases for the function signatures used by event callback props. Import them to annotate your handler functions explicitly.

TypeSignatureUsed by
BeforeActionHandler(action: Actions | string, config: IExecuteConfig) => boolean | voidonBeforeAction
AfterActionHandler(action: Actions | string, config: IExecuteConfig) => voidonAfterAction
BeforeCellHandler(cell: string) => boolean | voidonBeforeSelectionSet, onBeforeSelectionRemove, onBeforeFocusSet
AfterCellHandler(cell: string) => voidonAfterSelectionSet, onAfterSelectionRemove, onAfterFocusSet
BeforeEditHandler(cell: string, value: string) => boolean | voidonBeforeEditStart, onBeforeEditEnd
AfterEditHandler(cell: string, value: string) => voidonAfterEditStart, onAfterEditEnd
BeforeSheetHandler(sheet: ISheet) => boolean | voidonBeforeSheetChange
AfterSheetHandler(sheet: ISheet) => voidonAfterSheetChange

SpreadsheetConfigProps

type SpreadsheetConfigProps = Omit<
ISpreadsheetConfig,
"leftSplit" | "topSplit" | "dateFormat" | "timeFormat"
>;

Base type for component props. Exposes all ISpreadsheetConfig constructor options as flat props.

Re-exported upstream types

These types are re-exported from @dhx/ts-spreadsheet for convenience:

TypeDescription
ISpreadsheetMain spreadsheet widget instance interface.
ISpreadsheetConfigConstructor configuration interface.
ISheetSheet instance interface (used in sheet event callbacks).
IFormatsCustom number format definition.
IFilterRulesFilter rule configuration.
IFilterFilter instance interface.
IStylesListStyle definitions map.
IDataWithStylesData structure with embedded styles (used by serialize()/parse()).
ICellInfoCell information returned by widget methods.
FileFormatFile format for data loading (e.g. "json", "xlsx").
ToolbarBlocksToolbar block identifiers (e.g. "default", "undo", "font").
FilterConditionsEnum of available filter condition types.
IdGeneric identifier type (string | number).