JavaScript Data GridMerge cells
Merge adjacent cells, using the Ctrl+M shortcut or the context menu. Control merged cells, using Handsontable's API.
Overview
By merging, you can combine two or more adjacent cells into a single cell that spans several rows or columns.
Handsontable merges cells in the same way as Microsoft Excel: keeps only the upper-left value of the selected range and clears other values.
Cell merging happens on Handsontable's visual layer and doesn't affect your source data structure.
How to merge cells
To enable the merge cells feature, set the mergeCells
option to true
or to an array.
To initialize Handsontable with predefined merged cells, provide merged cells details in form of an array:
mergeCells: [{ row: 1, col: 1, rowspan: 2, colspan: 2 }]
Optimizing rendering of the wide/tall merged cells
When cells span thousands of rows or columns, scrolling may feel slower compared to unmerged cells. To improve performance, consider enabling the dedicated virtualization feature for merged cells, which is disabled by default.
To enable the merged cells virtualization mode, enable the virtualized
option:
mergeCells: {
virtualized: true,
cells: [{ row: 1, col: 1, rowspan: 200, colspan: 2 }]
}
The example below uses virtualized merged cells. It's also recommended to increase the buffer of rendered rows/columns to minimize the flickering effects.
Related keyboard shortcuts
Windows | macOS | Action | Excel | Sheets |
---|---|---|---|---|
Ctrl+M | Ctrl+M | Merge or unmerge the selected cells | ✗ | ✗ |