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.
It allows 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;
}
Press Enter to start editing
Function signature
The function signature allows spanning only 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:
Day
09:00 - 10:00
10:00 - 11:00
11:00 - 12:00
12:00 - 13:00
13:00 - 14:00
14:00 - 15:00
15:00 - 16:00
Monday
Maths
English
Lab
Lab
Music
Tuesday
Chemistry
Physics
Maths
Lab
Wednesday
Physics
English
Maths
Chemistry
Thursday
Music
Chemistry
Chemistry
English
Friday
Maths
Dance
Physics
English