Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 170 additions & 0 deletions doc/en/components/grids/_shared/cell-merging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
---
title: {Platform} {ComponentTitle} Cell Merging - {ProductName}
_description: Position and size columns in a more powerful way, using the multi-row layout functionality in the {ProductName} for {Platform} {ComponentTitle}. Check out examples and demos!
_keywords: cell merging, {Platform}, {ComponentKeywords}, {ProductName}, Infragistics
mentionedTypes: [{ComponentApiMembers}]
sharedComponents: ["Grid", "TreeGrid", "HierarchicalGrid"]
namespace: Infragistics.Controls
_canonicalLink: {CanonicalLinkToGridCellMerging}
---

# {Platform} {ComponentTitle} Cell Merging

The Ignite UI for {Platform} {ComponentTitle} provides a Cell Merging feature that combines two or more adjacent cells with the same value into a single, larger cell. Merging is applied vertically within a column and helps improve readability by reducing duplicate values. The feature can be configured to merge cells either by default matching data values or by applying a custom condition.

## {Platform} {ComponentTitle} Cell Merging Example

`sample="/{ComponentSample}/cell-merging", height="700", alt="{Platform} {ComponentTitle} Cell Merging Example"`

## Enabling and Using Cell Merging
Cell merging in the grid is controlled at two levels:
- Grid-level merge mode – determines when merging is applied.
- Column-level merge toggle – determines which columns can merge cells.

### Grid Merge Mode
The grid exposes a `cellMergeMode` property that accepts values from the `GridCellMergeMode` enum:
- `always` - Merges any adjacent cells that meet the merging condition, regardless of sort state.
- `onSort` - Merges adjacent cells only when the column is sorted **(default value)**.

```html
<@@igSelector [data]="data" [cellMergeMode]="cellMergeMode">
...
</@@igSelector>
```
```ts
protected cellMergeMode: GridCellMergeMode = 'always';
```

### Column Merge Toggle
At the column level, merging can be enabled or disabled with the `merge` property.

```html
<igx-column field="OrderID" [merge]="true"></igx-column>
<igx-column field="ShipperName" [merge]="false"></igx-column>
```

In the above example:
- The **OrderID** column will merge adjacent duplicate values.
- The **ShipperName** column will render normally without merging.

### Combined Example

```html
<@@igSelector [data]="data" [cellMergeMode]="cellMergeMode" [autoGenerate]="false">
<igx-column field="OrderID" header="Order ID" [merge]="true"></igx-column>
<igx-column field="ShipperName" header="Shipper Name" [merge]="true"></igx-column>
<igx-column field="Salesperson" header="Salesperson"></igx-column>
</@@igSelector>
```
```ts
protected cellMergeMode: GridCellMergeMode = 'onSort';
```
Here, the grid is set to merge only when columns are sorted, and both Category and Product columns are configured for merging.

## Custom Merge Conditions
In addition to the built-in `always` and `onSort` modes, the grid allows you to define a custom condition for merging cells through the `mergeStrategy` property. This strategy controls both how cells are compared and how merged ranges are calculated.

### Merge Strategy Interface
A custom merge strategy must implement the `IGridMergeStrategy` interface:

```ts
export interface IGridMergeStrategy {
merge: (
data: any[],
field: string,
comparer: (prevRecord: any, currentRecord: any, field: string) => boolean,
result: any[],
activeRowIndex?: number,
grid?: GridType
) => any[];

comparer: (prevRecord: any, record: any, field: string) => boolean;
}
```
- `merge` - defines how merged cells are produced.
- `comparer` - defines the condition to decide if two adjacent records should be merged.

<!-- ComponentStart: Grid, HierarchicalGrid -->
### Extending the Default Strategy

If you only want to customize part of the behavior (for example, the comparer logic), you can extend the built-in `DefaultMergeStrategy` and override the relevant methods.

```ts
export class MyCustomStrategy extends DefaultMergeStrategy {
/* Merge only cells within their respective projects */
public override comparer(prevRecord: any, record: any, field: string): boolean {
const a = prevRecord[field];
const b = record[field];
const projA = prevRecord['ProjectName'];
const projB = record['ProjectName'];
return a === b && projA === projB;
}
}
```
<!-- ComponentEnd: Grid, HierarchicalGrid -->
<!-- ComponentStart: TreeGrid -->
The `IgxTreeGrid` provides two built-in strategies that implement the `IGridMergeStrategy` interface: `DefaultTreeGridMergeStrategy` and `ByLevelTreeGridMergeStrategy`. `DefaultTreeGridMergeStrategy` merges all cells with the same value, regardless of their hierarchical level. In contrast, `ByLevelTreeGridMergeStrategy` only merges cells if they have the same value and are located at the same level, making level a required condition for merging.

### Extending the Default Strategy

If you only want to customize part of the behavior (for example, the comparer logic), you can extend one of the built-in strategies, either `DefaultTreeGridMergeStrategy` or `ByLevelTreeGridMergeStrategy`, and override the relevant methods.

```ts
export class MyCustomStrategy extends DefaultTreeGridMergeStrategy {
/* Merge only cells within their respective projects */
public override comparer(prevRecord: any, record: any, field: string): boolean {
const a = prevRecord[field];
const b = record[field];
const projA = prevRecord['ProjectName'];
const projB = record['ProjectName'];
return a === b && projA === projB;
}
}
```
<!-- ComponentEnd: TreeGrid -->

### Applying a Custom Strategy
Once defined, assign the strategy to the grid through the `mergeStrategy` property:
```html
<@@igSelector [data]="data" [mergeStrategy]="customStrategy">
<igx-column field="ActionID" [merge]="true"></igx-column>
<igx-column field="ProjectName" [merge]="true"></igx-column>
</@@igSelector>
```
```ts
protected customStrategy = new MyCustomStrategy();
```
<!-- ComponentStart: Grid -->
### Demo
`sample="/{ComponentSample}/cell-merging-custom", height="700", alt="{Platform} {ComponentTitle} Cell Merging Example"`
<!-- ComponentEnd: Grid -->

## Feature Integration
Due to the specific behavior of merged cells it has to be noted how exactly it ties together with some of the other features of the grid:
<!-- ComponentStart: Grid -->
- **Expand/Collapse**: if a feature (such as master-detail, grouping, etc.) generates a non-data row, then the cell merging is interrupted and the group will be split.
<!-- ComponentEnd: Grid -->
- **Excel export**: merged cells remain merged when exported to Excel.
- **Column pinning**: cells remain merged when a column is pinned and are displayed in the pinned area.
- **Row pinning**: cells merge only withing their containing area, i.e. cells of pinned rows merge only with cells of other pinned rows, while cells of unpinned rows merge only with cells of unpinned rows.
- **Navigation/Activation**: when a cell is active, all merged cells in the same row become single cells, i.e. their merge sequence is broken. This also includes activation via keyboard navigation.

>[!NOTE]
> If a merged cell is clicked, the closest cell from the merge sequence will become active.

- **Updating/Editing**: since activation breaks the merge sequence, only a single cell will be in edit mode.
- **Row selection**: if selected rows intersect merged cells, all related merged cells should be marked as part of the selection.

<!-- ComponentStart: Grid -->
## Limitations
|Known Limitations| Description|
| --- | --- |
| Cell merging is not supported in combination with Multi-row Layout. | Both span complex layouts that don't make sense when combined. A warning will be thrown if such invalid configuration is detected. |
<!-- ComponentEnd: Grid -->

## API References
* `{ComponentName}`

## Additional Resources
<!-- * [{ComponentName} Overview](data-grid.md)
-->
22 changes: 18 additions & 4 deletions docfx/en/components/toc.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@
"name": "Grid",
"href": "grids/data-grid.md",
"items": [
{
"exclude": ["Angular"],
"name": "Cell Merging",
"href": "grids/grid/cell-merging.md",
"status": "NEW"
},
{
"exclude": ["Angular"],
"name": "Clipboard Interactions",
Expand Down Expand Up @@ -396,6 +402,12 @@
"name": "Hierarchical Grid",
"href": "grids/hierarchical-grid/overview.md",
"items": [
{
"exclude": ["Angular"],
"name": "Cell Merging",
"href": "grids/hierarchical-grid/cell-merging.md",
"status": "NEW"
},
{
"exclude": ["Angular"],
"name": "Collapsible Column Groups",
Expand Down Expand Up @@ -618,6 +630,12 @@
"name": "Tree Grid",
"href": "grids/tree-grid/overview.md",
"items": [
{
"exclude": ["Angular"],
"name": "Cell Merging",
"href": "grids/tree-grid/cell-merging.md",
"status": "NEW"
},
{
"exclude": ["Angular"],
"name": "Clipboard Interactions",
Expand Down Expand Up @@ -900,10 +918,6 @@
"href": "grids/data-grid/cell-editing.md",
"status": ""
},
{
"name": "Cell Merging",
"href": "grids/data-grid/cell-merging.md"
},
{
"name": "Cell Selection",
"href": "grids/data-grid/cell-selection.md",
Expand Down