Skip to content
+

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: