Data Grid - Column spanning
Span cells across several columns.
By default, each cell takes up the width of one
column. You can modify this behavior with column
spanning, which makes it possible for cells to
span multiple columns. This is very close to the
"column spanning" in an HTML
<table>.
To change the number of columns a cell should
span, use the colSpan property
available in GridColDef:
interface GridColDef {
/**
* Number of columns a cell should span.
* @default 1
*/
colSpan?: number | ((params: GridCellParams<R, V, F>) => number | undefined);
…
}
Number signature
The number signature sets all cells in the column to span a given number of columns.
interface GridColDef {
colSpan?: number;
}
Function signature
The function signature makes it possible to only
span specific cells in the column. The function
receives
GridCellParams
as argument.
interface GridColDef {
colSpan?: (params: GridCellParams<R, V, F>) => number | undefined;
}
Function signature can also be useful to derive
colSpan value from row data: