# Angular Grid Row Spanning

The row spanning feature of the [Kendo UI for Angular Grid](https://www.telerik.com/kendo-angular-ui-develop/components/grid) enables you to span the cells in a particular column over multiple rows. This functionality is identical to "cell merging" in Excel or "row spanning" in HTML tables.

## Setup

To enable the built-in row spanning functionality of the Kendo UI for Angular Grid, set the [`cellRowspan`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/columncomponent#cellrowspan) property of the desired [`ColumnComponent`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/columncomponent) to `true`. The corresponding column will use a default function that spans consecutive Grid cells with the same value over multiple rows.

The following example demonstrates the default row spanning functionality and how it behaves with the different [data operations](https://www.telerik.com/kendo-angular-ui-develop/components/grid/data-operations) of the Grid.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/grid/row-spanning/source.txt)

## Custom Row Spanning

The `cellRowspan` property allows you to customize the default behavior of the row spanning functionality by defining a custom [`CellRowspanFn`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/cellrowspanfn) function. The callback is executed for each data row in a given Grid column and returns a number that determines the `rowspan` for each column cell.

> When a given cell has a certain `rowspan` applied, the next cells that get spanned based on the `rowspan` value are not rendered in the Grid and are omitted from the callback's following execution.

The `CellRowspanFn` callback provides information about the associated [`RowArgs`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/rowargs) instance, `ColumnComponent` and the currently displayed data in the Grid:

```ts
public rowspanCallback: CellRowspanFn = (row, column, data) => {
    return 2;
}
```

> The `CellRowspanFn` callback is executed each time the rendered Grid data is updated as a result of a data operation or editing.

The callback grants the freedom to implement any custom logic for spanning the desired cells depending on the current Grid state and considering the requirements of the application.

The following example implements a custom function that spans consecutive Grid cells with the same `CategoryID` and sets a suitable template for the spanned cells.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/grid/row-spanning/custom/source.txt)

### Custom Row Spanning with Grouping

When grouping is configured for the Grid, the `CellRowspanFn` callback exposes additional information about the group, in which each data row is contained. This enables you to adjust the custom row spanning function depending on the defined groups.

You can obtain the associated group of a row from the `group` field of the `dataItem` that the `RowArgs` parameter of the function provides:

```ts
public rowspanCallback: CellRowspanFn = (row, column, data) => {
    const group = row.dataItem.group;
    ...
}
```

You can use this information to ensure that the custom callback for the `cellRowspan` property takes into account the defined groups and correctly applies the desired `rowspan` to the grouped cells.

The following example demonstrates how to set a suitable `rowspan` based on the grouped Grid rows with custom logic.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/grid/row-spanning/custom-grouping/source.txt)

## Suggested Links

* [Kendo UI for Angular Grid Grouping Basics](https://www.telerik.com/kendo-angular-ui-develop/components/grid/grouping/basics)
* [Kendo UI for Angular Grid Spanned Columns](https://www.telerik.com/kendo-angular-ui-develop/components/grid/columns/spanned)
* [API Reference of the ColumnComponent](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/columncomponent)
* [API Reference of the GridComponent](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent)
* [API Index of the Grid](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api)
