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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPZYQAumujy5kXaOKurr6zgTP2krHrFVXi2kj8seRYrlvq2GssUjReh5MiVpQbLFQNy9HsmcasqpBNVsXytWTw0ZDjA=

Grid

import { Grid, GridCellEditor } from '@dxos/react-ui-grid';
Terminal window
npm install @dxos/react-ui-grid

A grid is rows and columns of cells that the user selects and edits. Grid is the one under Composer’s sheets and tables. It draws only the cells in view, so it stays fast for large data.

Grid also handles selection, keyboard movement and resizing. You pass it a getCells function, and it calls the function for the cells it shows.

Part What it is
Grid.Root The root, which requires the grid’s id. It holds which cell is being edited (editing, onEditingChange)
Grid.Content The grid itself. getCells gives it the cells in view
GridCellEditor An editor that opens over the cell being edited

Grid.Content takes these props:

Prop Type Effect
getCells (range, plane) => cells Returns a plane’s cells, keyed col,row, each with a value
initialCells DxGridCells Sets cells by plane, keyed col,row, shown wherever getCells gives no cell. { grid: {} } by default
frozen DxGridFrozenAxes Sets how many rows or columns each frozen edge plane has
columnDefault GridContentProps['columnDefault'] Sets the default column sizes, by plane
rowDefault GridContentProps['rowDefault'] Sets the default row sizes, by plane
columns DxGridAxisMeta Sets the size of single columns, by plane and index
rows DxGridAxisMeta Sets the size of single rows, by plane and index
limitColumns number Sets how far the grid scrolls across. No limit by default
limitRows number Sets how far the grid scrolls down. No limit by default
overscroll 'trap' | 'inline' | 'block' Sets which wheel scrolls stay in the grid at its edges
focusIndicatorVariant 'sheet' | 'stack' Sets the width of the focus indicator, a hairline for 'sheet' or a thick line for 'stack'. 'sheet' by default
activeRefs string Sets refs, separated by spaces. The grid highlights each cell whose dataRefs holds one. Empty by default
addressing GridAddressing Names each cell by its row and column identity, so the grid can share the selection with collaborators
onSelect (event) => void The user selected a range of cells
onAxisResize (event) => void The user resized a row or a column

A grid has planes. The main plane is grid. Frozen planes sit at its edges, for headers that stay in place as the grid scrolls.

A new getCells makes the grid ask again, so build it from your state.

GridCellEditor opens over the cell when the user double-clicks or types.

  • getCellContent gives the editor its starting text.
  • onBlur hands back the new text.
  • editorKeys closes the editor on Enter or Tab.
  • refocus moves the focus on, as a spreadsheet does.

Example (Editing a budget sheet)

import {
function useCallback<T extends Function>(callback: T, deps: React.DependencyList): T

useCallback will return a memoized version of the callback that only changes if one of the inputs has changed.

useCallback
,
function useMemo<T>(factory: () => T, deps: React.DependencyList): T

useMemo will only recompute the memoized value when one of the deps has changed.

@version ― 16.8.0

@see ― https://react.dev/reference/react/useMemo

useMemo
,
function useState<S>(initialState: S | (() => S)): [S, React.Dispatch<React.SetStateAction<S>>] (+1 overload)

Returns a stateful value, and a function to update it.

@version ― 16.8.0

@see ― https://react.dev/reference/react/useState

useState
} from 'react';
import { type
type DxGridElement = DxGrid
DxGridElement
, type
type DxGridPlane = "grid" | DxGridFrozenPlane | "fixedStartStart" | "fixedStartEnd" | "fixedEndStart" | "fixedEndEnd"
DxGridPlane
, type
type DxGridPlaneCells = {
[x: `${string},${string}`]: DxGridCellValue;
}
DxGridPlaneCells
, type
type EditorKeyHandler = (value: string | undefined, event: EditorKeyEvent) => void
EditorKeyHandler
,
const Grid: {
Root: typeof GridRoot;
Content: React.ForwardRefExoticComponent<Omit<GridContentProps, "ref"> & React.RefAttributes<DxGrid>>;
}
Grid
,
const GridCellEditor: ({ extensions, getCellContent, onBlur, slots }: GridCellEditorProps) => React.JSX.Element | null
GridCellEditor
, type
type GridContentProps = Omit<Omit<React.HTMLAttributes<DxGrid>, "onSelect" | "onAxisResize" | "onEdit" | "gridId" | "rowDefault" | "columnDefault" | "rows" | "columns" | "initialCells" | "mode" | "limitColumns" | "limitRows" | "frozen" | "overscroll" | "activeRefs" | "remoteSelections" | "focusIndicatorVariant" | "getCells" | "getSelection" | "getFocusedCell" | "moveSelection" | "setSelection" | "updateCells" | "setFocus" | "refocus" | "snapPosToFocusedCell" | "scrollToCoord" | "scrollToColumn" | "scrollToRow" | "scrollToEndRow" | "render" | ... 15 more ... | "updateComplete"> & EventListeners<...> & Partial<...> & React.RefAttributes<...>, "onEdit" | ... 2 more ... | "remoteSelections"> & {
...;
}
GridContentProps
, type
type GridEditing = {
index: DxEditRequest["cellIndex"];
cellElement: DxEditRequest["cellElement"];
initialContent: DxEditRequest["initialContent"];
} | null
GridEditing
,
const editorKeys: ({ onNav, onClose }: EditorKeysProps) => Extension
editorKeys
,
function parseCellIndex(index: DxGridCellIndex): DxGridPosition (+1 overload)
parseCellIndex
} from '@dxos/react-ui-grid';
const
const COLUMNS: string[]
COLUMNS
= ['Item', 'Q1', 'Q2', 'Q3', 'Total'];
const
const ROWS: string[][]
ROWS
= [
['Hosting', '1200', '1350', '1400'],
['Design', '800', '650', '900'],
['Support', '400', '420', '380'],
['Travel', '300', '0', '550'],
// Blank rows to fill in, past the bottom of a small frame, as in a spreadsheet.
...
var Array: ArrayConstructor
Array
.
ArrayConstructor.from<unknown, string[]>(iterable: Iterable<unknown> | ArrayLike<unknown>, mapfn: (v: unknown, k: number) => string[], thisArg?: any): string[][] (+3 overloads)

Creates an array from an iterable object.

@param ― iterable An iterable object to convert to an array.

@param ― mapfn A mapping function to call on every element of the array.

@param ― thisArg Value of 'this' used to invoke the mapfn.

from
({
ArrayLike<T>.length: number
length
: 40 }, () => ['', '', '', '']),
];
/** Blank columns past the totals, so the sheet runs off the right edge too. */
const
const BLANK_COLUMNS: 6

Blank columns past the totals, so the sheet runs off the right edge too.

BLANK_COLUMNS
= 6;
const
const TOTAL: number
TOTAL
=
const COLUMNS: string[]
COLUMNS
.
Array<string>.length: number

Gets or sets the length of the array. This is a number one higher than the highest index in the array.

length
- 1;
/** Each row's total, from the quarters before it; a cell that is not a number counts as zero, and a blank row has none. */
const
const total: (row: string[]) => string

Each row's total, from the quarters before it; a cell that is not a number counts as zero, and a blank row has none.

total
= (
row: string[]
row
: string[]) =>
row: string[]
row
.
Array<string>.every<"">(predicate: (value: string, index: number, array: string[]) => value is "", thisArg?: any): this is S[] (+1 overload)

Determines whether all the members of an array satisfy the specified test.

@param ― predicate A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array.

@param ― thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

every
((
value: string
value
) =>
value: string
value
=== '')
? ''
:
var String: StringConstructor
(value?: any) => string

Allows manipulation and formatting of text strings and determination and location of substrings within strings.

String
(
row: string[]
row
.
Array<string>.slice(start?: number, end?: number): string[]

Returns a copy of a section of an array. For both start and end, a negative index can be used to indicate an offset from the end of the array. For example, -2 refers to the second to last element of the array.

@param ― start The beginning index of the specified portion of the array. If start is undefined, then the slice begins at index 0.

@param ― end The end index of the specified portion of the array. This is exclusive of the element at the index 'end'. If end is undefined, then the slice extends to the end of the array.

slice
(1,
const TOTAL: number
TOTAL
)
.
Array<string>.reduce<number>(callbackfn: (previousValue: number, currentValue: string, currentIndex: number, array: string[]) => number, initialValue: number): number (+2 overloads)

Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

@param ― callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.

@param ― initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.

reduce
((
sum: number
sum
,
value: string
value
) =>
sum: number
sum
+ (
var Number: NumberConstructor
(value?: any) => number

An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.

Number
(
value: string
value
) || 0), 0),
);
/** The cells of a plane, keyed `col,row`: the header row is a frozen plane, and the values are the grid plane. */
const
const toCells: (rows: string[][], plane: DxGridPlane) => DxGridPlaneCells

The cells of a plane, keyed col,row: the header row is a frozen plane, and the values are the grid plane.

toCells
= (
rows: string[][]
rows
: string[][],
plane: DxGridPlane
plane
:
type DxGridPlane = "grid" | DxGridFrozenPlane | "fixedStartStart" | "fixedStartEnd" | "fixedEndStart" | "fixedEndEnd"
DxGridPlane
):
type DxGridPlaneCells = {
[x: `${string},${string}`]: DxGridCellValue;
}
DxGridPlaneCells
=> {
if (
plane: DxGridPlane
plane
=== 'frozenRowsStart') {
return
var Object: ObjectConstructor

Provides functionality common to all JavaScript objects.

Object
.
ObjectConstructor.fromEntries<{
value: string;
readonly: true;
}>(entries: Iterable<readonly [PropertyKey, {
value: string;
readonly: true;
}]>): {
[k: string]: {
value: string;
readonly: true;
};
} (+1 overload)

Returns an object created by key-value entries for properties and methods

@param ― entries An iterable object that contains key-value entries for properties and methods.

fromEntries
(
const COLUMNS: string[]
COLUMNS
.
Array<string>.map<[string, {
value: string;
readonly: true;
}]>(callbackfn: (value: string, index: number, array: string[]) => [string, {
value: string;
readonly: true;
}], thisArg?: any): [string, {
value: string;
readonly: true;
}][]

Calls a defined callback function on each element of an array, and returns an array that contains the results.

@param ― callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.

@param ― thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

map
((
label: string
label
,
col: number
col
) => [
`${
col: number
col
},0`,
{
value: string
value
:
label: string
label
,
readonly: true
readonly
: true },
]),
);
}
return
var Object: ObjectConstructor

Provides functionality common to all JavaScript objects.

Object
.
ObjectConstructor.fromEntries(entries: Iterable<readonly any[]>): any (+1 overload)

Returns an object created by key-value entries for properties and methods

@param ― entries An iterable object that contains key-value entries for properties and methods.

fromEntries
(
rows: string[][]
rows
.
Array<string[]>.flatMap<(string | {
value: string;
})[] | [string, {
value: string;
readonly: true;
}], undefined>(callback: (this: undefined, value: string[], index: number, array: string[][]) => (string | {
value: string;
})[] | [string, {
value: string;
readonly: true;
}] | readonly ((string | {
value: string;
})[] | [string, {
value: string;
readonly: true;
}])[], thisArg?: undefined): ((string | {
value: string;
})[] | [string, {
value: string;
readonly: true;
}])[]

Calls a defined callback function on each element of an array. Then, flattens the result into a new array. This is identical to a map followed by flat with depth 1.

@param ― callback A function that accepts up to three arguments. The flatMap method calls the callback function one time for each element in the array.

@param ― thisArg An object to which the this keyword can refer in the callback function. If thisArg is omitted, undefined is used as the this value.

flatMap
((
row: string[]
row
,
rowIndex: number
rowIndex
) => [
...
row: string[]
row
.
Array<string>.map<(string | {
value: string;
})[]>(callbackfn: (value: string, index: number, array: string[]) => (string | {
value: string;
})[], thisArg?: any): (string | {
value: string;
})[][]

Calls a defined callback function on each element of an array, and returns an array that contains the results.

@param ― callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.

@param ― thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

map
((
value: string
value
,
col: number
col
) => [`${
col: number
col
},${
rowIndex: number
rowIndex
}`, {
value: string
value
}]),
[`${
const TOTAL: number
TOTAL
},${
rowIndex: number
rowIndex
}`, {
value: string
value
:
const total: (row: string[]) => string

Each row's total, from the quarters before it; a cell that is not a number counts as zero, and a blank row has none.

total
(
row: string[]
row
),
readonly: true
readonly
: true }],
]),
);
};
const
const frozen: {
frozenRowsStart: number;
}
frozen
= {
frozenRowsStart: number
frozenRowsStart
: 1 };
const
const columnDefault: {
grid: {
size: number;
};
}
columnDefault
= {
grid: {
size: number;
}
grid
: {
size: number
size
: 112 } };
const
const rowDefault: {
frozenRowsStart: {
size: number;
readonly: boolean;
};
grid: {
size: number;
};
}
rowDefault
= {
frozenRowsStart: {
size: number;
readonly: boolean;
}
frozenRowsStart
: {
size: number
size
: 32,
readonly: boolean
readonly
: true },
grid: {
size: number;
}
grid
: {
size: number
size
: 32 },
};
/** A small budget: double-click or type into a cell to edit it, and the row's total follows. */
export const
const BudgetSheet: () => React.JSX.Element

A small budget: double-click or type into a cell to edit it, and the row's total follows.

BudgetSheet
= () => {
const [
const rows: string[][]
rows
,
const setRows: React.Dispatch<React.SetStateAction<string[][]>>
setRows
] =
useState<string[][]>(initialState: string[][] | (() => string[][])): [string[][], React.Dispatch<React.SetStateAction<string[][]>>] (+1 overload)

Returns a stateful value, and a function to update it.

@version ― 16.8.0

@see ― https://react.dev/reference/react/useState

useState
(
const ROWS: string[][]
ROWS
);
const [
const editing: GridEditing
editing
,
const setEditing: React.Dispatch<React.SetStateAction<GridEditing>>
setEditing
] =
useState<GridEditing>(initialState: GridEditing | (() => GridEditing)): [GridEditing, React.Dispatch<React.SetStateAction<GridEditing>>] (+1 overload)

Returns a stateful value, and a function to update it.

@version ― 16.8.0

@see ― https://react.dev/reference/react/useState

useState
<
type GridEditing = {
index: DxEditRequest["cellIndex"];
cellElement: DxEditRequest["cellElement"];
initialContent: DxEditRequest["initialContent"];
} | null
GridEditing
>(null);
const [
const grid: DxGrid | null
grid
,
const setGrid: React.Dispatch<React.SetStateAction<DxGrid | null>>
setGrid
] =
useState<DxGrid | null>(initialState: DxGrid | (() => DxGrid | null) | null): [DxGrid | null, React.Dispatch<React.SetStateAction<DxGrid | null>>] (+1 overload)

Returns a stateful value, and a function to update it.

@version ― 16.8.0

@see ― https://react.dev/reference/react/useState

useState
<
type DxGridElement = DxGrid
DxGridElement
| null>(null);
// The grid asks for the cells it shows; a new callback makes it ask again.
const
const getCells: (nextRange: DxGridPlaneRange, plane: DxGridPlane) => DxGridPlaneCells
getCells
=
useCallback<(nextRange: DxGridPlaneRange, plane: DxGridPlane) => DxGridPlaneCells>(callback: (nextRange: DxGridPlaneRange, plane: DxGridPlane) => DxGridPlaneCells, deps: React.DependencyList): (nextRange: DxGridPlaneRange, plane: DxGridPlane) => DxGridPlaneCells

useCallback will return a memoized version of the callback that only changes if one of the inputs has changed.

useCallback
<
type NonNullable<T> = T & {}

Exclude null and undefined from T

NonNullable
<
type GridContentProps = Omit<Omit<React.HTMLAttributes<DxGrid>, "onSelect" | "onAxisResize" | "onEdit" | "gridId" | "rowDefault" | "columnDefault" | "rows" | "columns" | "initialCells" | "mode" | "limitColumns" | "limitRows" | "frozen" | "overscroll" | "activeRefs" | "remoteSelections" | "focusIndicatorVariant" | "getCells" | "getSelection" | "getFocusedCell" | "moveSelection" | "setSelection" | "updateCells" | "setFocus" | "refocus" | "snapPosToFocusedCell" | "scrollToCoord" | "scrollToColumn" | "scrollToRow" | "scrollToEndRow" | "render" | ... 15 more ... | "updateComplete"> & EventListeners<...> & Partial<...> & React.RefAttributes<...>, "onEdit" | ... 2 more ... | "remoteSelections"> & {
...;
}
GridContentProps
['getCells']>>(
(
_range: DxGridPlaneRange
_range
,
plane: DxGridPlane
plane
) =>
const toCells: (rows: string[][], plane: DxGridPlane) => DxGridPlaneCells

The cells of a plane, keyed col,row: the header row is a frozen plane, and the values are the grid plane.

toCells
(
const rows: string[][]
rows
,
plane: DxGridPlane
plane
),
[
const rows: string[][]
rows
],
);
const
const handleBlur: (value?: string) => void
handleBlur
= (
value: string | undefined
value
?: string) => {
if (
value: string | undefined
value
!==
var undefined
undefined
&&
const editing: GridEditing
editing
) {
const {
const col: number
col
,
const row: number
row
} =
function parseCellIndex(index: DxGridCellIndex): DxGridPosition (+1 overload)
parseCellIndex
(
const editing: {
index: DxEditRequest["cellIndex"];
cellElement: DxEditRequest["cellElement"];
initialContent: DxEditRequest["initialContent"];
}
editing
.
index: `grid,${string},${string}` | `frozenColsStart,${string},${string}` | `frozenColsEnd,${string},${string}` | `frozenRowsStart,${string},${string}` | `frozenRowsEnd,${string},${string}` | `fixedStartStart,${string},${string}` | `fixedStartEnd,${string},${string}` | `fixedEndStart,${string},${string}` | `fixedEndEnd,${string},${string}`
index
);
const setRows: (value: React.SetStateAction<string[][]>) => void
setRows
((
current: string[][]
current
) =>
current: string[][]
current
.
Array<string[]>.map<string[]>(callbackfn: (value: string[], index: number, array: string[][]) => string[], thisArg?: any): string[][]

Calls a defined callback function on each element of an array, and returns an array that contains the results.

@param ― callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.

@param ― thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

map
((
cells: string[]
cells
,
rowIndex: number
rowIndex
) =>
rowIndex: number
rowIndex
===
const row: number
row
?
cells: string[]
cells
.
Array<string>.map<string>(callbackfn: (value: string, index: number, array: string[]) => string, thisArg?: any): string[]

Calls a defined callback function on each element of an array, and returns an array that contains the results.

@param ― callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.

@param ― thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

map
((
cell: string
cell
,
column: number
column
) => (
column: number
column
===
const col: number
col
?
value: string
value
:
cell: string
cell
))
:
cells: string[]
cells
,
),
);
}
};
// Enter and Tab close the editor and move the focus down or across, as a spreadsheet does.
const
const handleClose: EditorKeyHandler
handleClose
=
useCallback<EditorKeyHandler>(callback: EditorKeyHandler, deps: React.DependencyList): EditorKeyHandler

useCallback will return a memoized version of the callback that only changes if one of the inputs has changed.

useCallback
<
type EditorKeyHandler = (value: string | undefined, event: EditorKeyEvent) => void
EditorKeyHandler
>(
(
_value: string | undefined
_value
,
event: EditorKeyEvent
event
) => {
if (
event: EditorKeyEvent
event
) {
const grid: DxGrid | null
grid
?.
DxGrid.refocus(increment?: "col" | "row" | undefined, delta?: 1 | -1 | 0): void

Moves focus to the cell with actual focus, otherwise moves focus to the viewport.

refocus
(
event: EditorKeyEvent
event
.
key: string

See the DOM Level 3 Events spec. for possible values

key
=== 'Tab' ? 'col' : 'row',
event: EditorKeyEvent
event
.
shift?: boolean | undefined
shift
? -1 : 1,
);
}
},
[
const grid: DxGrid | null
grid
],
);
const
const extensions: Extension[]
extensions
=
useMemo<Extension[]>(factory: () => Extension[], deps: React.DependencyList): Extension[]

useMemo will only recompute the memoized value when one of the deps has changed.

@version ― 16.8.0

@see ― https://react.dev/reference/react/useMemo

useMemo
(
() => [
function editorKeys({ onNav, onClose }: EditorKeysProps): Extension
editorKeys
({
onClose: EditorKeyHandler
onClose
:
const handleClose: EditorKeyHandler
handleClose
})],
[
const handleClose: EditorKeyHandler
handleClose
],
);
return (
<
const Grid: {
Root: typeof GridRoot;
Content: React.ForwardRefExoticComponent<Omit<GridContentProps, "ref"> & React.RefAttributes<DxGrid>>;
}
Grid
.
type Root: typeof GridRoot
Root
id: string
id
='budget'
editing?: GridEditing | undefined
editing
={
const editing: GridEditing
editing
}
onEditingChange?: ((nextEditing: GridEditing) => void) | undefined
onEditingChange
={
const setEditing: React.Dispatch<React.SetStateAction<GridEditing>>
setEditing
}>
<
const GridCellEditor: ({ extensions, getCellContent, onBlur, slots }: GridCellEditorProps) => React.JSX.Element | null
GridCellEditor
getCellContent: (index: DxGridCellIndex) => string | undefined
getCellContent
={(
index: `grid,${string},${string}` | `frozenColsStart,${string},${string}` | `frozenColsEnd,${string},${string}` | `frozenRowsStart,${string},${string}` | `frozenRowsEnd,${string},${string}` | `fixedStartStart,${string},${string}` | `fixedStartEnd,${string},${string}` | `fixedEndStart,${string},${string}` | `fixedEndEnd,${string},${string}`
index
) =>
const rows: string[][]
rows
[
function parseCellIndex(index: DxGridCellIndex): DxGridPosition (+1 overload)
parseCellIndex
(
index: `grid,${string},${string}` | `frozenColsStart,${string},${string}` | `frozenColsEnd,${string},${string}` | `frozenRowsStart,${string},${string}` | `frozenRowsEnd,${string},${string}` | `fixedStartStart,${string},${string}` | `fixedStartEnd,${string},${string}` | `fixedEndStart,${string},${string}` | `fixedEndEnd,${string},${string}`
index
).
row: number
row
]?.[
function parseCellIndex(index: DxGridCellIndex): DxGridPosition (+1 overload)
parseCellIndex
(
index: `grid,${string},${string}` | `frozenColsStart,${string},${string}` | `frozenColsEnd,${string},${string}` | `frozenRowsStart,${string},${string}` | `frozenRowsEnd,${string},${string}` | `fixedStartStart,${string},${string}` | `fixedStartEnd,${string},${string}` | `fixedEndStart,${string},${string}` | `fixedEndEnd,${string},${string}`
index
).
col: number
col
]
}
extensions?: Extension | undefined
extensions
={
const extensions: Extension[]
extensions
}
onBlur?: EditorBlurHandler | undefined
onBlur
={
const handleBlur: (value?: string) => void
handleBlur
}
/>
<
const Grid: {
Root: typeof GridRoot;
Content: React.ForwardRefExoticComponent<Omit<GridContentProps, "ref"> & React.RefAttributes<DxGrid>>;
}
Grid
.
type Content: React.ForwardRefExoticComponent<Omit<GridContentProps, "ref"> & React.RefAttributes<DxGrid>>
Content
RefAttributes<DxGrid>.ref?: React.Ref<DxGrid> | undefined

Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

ref
={
const setGrid: React.Dispatch<React.SetStateAction<DxGrid | null>>
setGrid
}
limitColumns?: number | undefined
limitColumns
={
const COLUMNS: string[]
COLUMNS
.
Array<string>.length: number

Gets or sets the length of the array. This is a number one higher than the highest index in the array.

length
+
const BLANK_COLUMNS: 6

Blank columns past the totals, so the sheet runs off the right edge too.

BLANK_COLUMNS
}
limitRows?: number | undefined
limitRows
={
const rows: string[][]
rows
.
Array<string[]>.length: number

Gets or sets the length of the array. This is a number one higher than the highest index in the array.

length
}
frozen?: Partial<Record<DxGridFrozenPlane, number>> | undefined
frozen
={
const frozen: {
frozenRowsStart: number;
}
frozen
}
columnDefault?: Partial<DxGridPlaneRecord<"frozenColsStart" | "frozenColsEnd", Partial<DxGridAxisMetaProps>>> | undefined
columnDefault
={
const columnDefault: {
grid: {
size: number;
};
}
columnDefault
}
rowDefault?: Partial<DxGridPlaneRecord<"frozenRowsStart" | "frozenRowsEnd", Partial<DxGridAxisMetaProps>>> | undefined
rowDefault
={
const rowDefault: {
frozenRowsStart: {
size: number;
readonly: boolean;
};
grid: {
size: number;
};
}
rowDefault
}
getCells?: ((nextRange: DxGridPlaneRange, plane: DxGridPlane) => DxGridPlaneCells) | null | undefined

When this function is defined, it is used first to try to get a value for a cell, and otherwise will fall back to cells.

getCells
={
const getCells: (nextRange: DxGridPlaneRange, plane: DxGridPlane) => DxGridPlaneCells
getCells
}
// Wheel and trackpad scrolls stay in the grid: no page scroll, no back/forward swipe.
overscroll?: DxGridOverscroll
overscroll
='trap'
/>
</
const Grid: {
Root: typeof GridRoot;
Content: React.ForwardRefExoticComponent<Omit<GridContentProps, "ref"> & React.RefAttributes<DxGrid>>;
}
Grid
.
type Root: typeof GridRoot
Root
>
);
};

toCells returns the header row for the frozenRowsStart plane and the values for the grid plane. handleBlur writes the new text into rows. That makes a new getCells, so the grid asks again and the row’s total follows.

Grid.Content also gets three props that make the sheet behave like a spreadsheet:

  • limitRows is the length of rows, which ends in 40 blank rows for the user to fill in.
  • limitColumns runs six columns past the data, so the sheet runs off the right edge. handleBlur writes only into a row’s four cells, so it drops text typed in a blank column.
  • overscroll='trap' keeps wheel and trackpad scrolls in the grid, so the page neither scrolls nor swipes back.

The story at the top of this page runs this example.