Skip to content

Plugin: MergeCells

Description

Plugin, which allows merging cells in the table (using the initial configuration, API or context menu).

Example

const hot = new Handsontable(document.getElementById('example'), {
data: getData(),
mergeCells: [
{row: 0, col: 3, rowspan: 3, colspan: 3},
{row: 2, col: 6, rowspan: 2, colspan: 2},
{row: 4, col: 8, rowspan: 3, colspan: 3}
],

Options

mergeCells

Source code

mergeCells.mergeCells : boolean | Array<object>

The mergeCells option configures the MergeCells plugin.

You can set the mergeCells option to one of the following:

SettingDescription
trueEnable the MergeCells plugin
falseDisable the MergeCells plugin
An array of objects- Enable the MergeCells plugin
- Merge specific cells at initialization
{ virtualized: true }Enable the MergeCells plugin with enabled virtualization mode

To merge specific cells at Handsontable’s initialization, set the mergeCells option to an array of objects, with the following properties:

PropertyDescription
rowThe row index of the merged section’s beginning
colThe column index of the merged section’s beginning
rowspanThe width (as a number of rows) of the merged section
colspanThe height (as a number of columns ) of the merged section

This option can only be set at the grid level. It has no effect when set in the columns, cells, or cell options.

Read more:

Default: false
Example

// enable the `MergeCells` plugin
mergeCells: true,
// enable the `MergeCells` plugin
// and merge specific cells at initialization
mergeCells: [
// merge cells from cell (1,1) to cell (3,3)
{row: 1, col: 1, rowspan: 3, colspan: 3},
// merge cells from cell (3,4) to cell (2,2)
{row: 3, col: 4, rowspan: 2, colspan: 2},
// merge cells from cell (5,6) to cell (3,3)
{row: 5, col: 6, rowspan: 3, colspan: 3}
],
// enable the `MergeCells` plugin with enabled virtualization mode
// and merge specific cells at initialization
mergeCells: {
virtualized: true,
cells: [
// merge cells from cell (1,1) to cell (3,3)
{row: 1, col: 1, rowspan: 3, colspan: 3},
// merge cells from cell (3,4) to cell (2,2)
{row: 3, col: 4, rowspan: 2, colspan: 2},
// merge cells from cell (5,6) to cell (3,3)
{row: 5, col: 6, rowspan: 3, colspan: 3}
],
},

Methods

clearCollections

Source code

mergeCells.clearCollections()

Clears the merged cells from the merged cell container.

disablePlugin

Source code

mergeCells.disablePlugin()

Disables the plugin functionality for this Handsontable instance.

enablePlugin

Source code

mergeCells.enablePlugin()

Enables the plugin functionality for this Handsontable instance.

isEnabled

Source code

mergeCells.isEnabled() ⇒ boolean

Checks if the plugin is enabled in the handsontable settings. This method is executed in Hooks#beforeInit hook and if it returns true then the MergeCells#enablePlugin method is called.

merge

Source code

mergeCells.merge(startRow, startColumn, endRow, endColumn)

Merges the specified range.

Emits: Hooks#event:beforeMergeCells, Hooks#event:afterMergeCells

ParamTypeDescription
startRownumberStart row of the merged cell.
startColumnnumberStart column of the merged cell.
endRownumberEnd row of the merged cell.
endColumnnumberEnd column of the merged cell.

mergeSelection

Source code

mergeCells.mergeSelection([cellRange])

Merges the selection provided as a cell range.

ParamTypeDescription
[cellRange]CellRangeoptional Selection cell range.

unmerge

Source code

mergeCells.unmerge(startRow, startColumn, endRow, endColumn)

Unmerges the merged cell in the provided range.

Emits: Hooks#event:beforeUnmergeCells, Hooks#event:afterUnmergeCells

ParamTypeDescription
startRownumberStart row of the merged cell.
startColumnnumberStart column of the merged cell.
endRownumberEnd row of the merged cell.
endColumnnumberEnd column of the merged cell.

unmergeSelection

Source code

mergeCells.unmergeSelection([cellRange])

Unmerges the selection provided as a cell range.

ParamTypeDescription
[cellRange]CellRangeoptional Selection cell range.

updatePlugin

Source code

mergeCells.updatePlugin()

Updates the plugin’s state.

This method is executed when updateSettings() is invoked with any of the following configuration options: