Skip to content

MergedCellsCollection

Description

Defines a container object for the merged cells.

Description

Initializes the cells collection with references to the MergeCells plugin and the Handsontable instance.

Members

mergedCells

Source code

mergedCellsCollection.mergedCells : Array<MergedCellCoords>

Array of merged cells.

mergedCellsMatrix

Source code

mergedCellsCollection.mergedCellsMatrix : Array

Matrix of cells (row, col) that points to the instances of the MergedCellCoords objects.

Methods

add

Source code

mergedCellsCollection.add(mergedCellInfo, [auto]) ⇒ MergedCellCoords | boolean

Add a merged cell to the container.

ParamTypeDefaultDescription
mergedCellInfoobjectThe merged cell information object. Has to contain row, col, colspan and rowspan properties.
[auto]booleanfalseoptional true if called internally by the plugin (usually in batch).

Returns: MergedCellCoords | boolean - Returns the new merged cell on success and false on failure.

addOutsideMatrix

Source code

mergedCellsCollection.addOutsideMatrix(mergedCellInfo) ⇒ MergedCellCoords

Adds a merged cell to the list without placing it in the lookup matrix. It is for a merge whose rows are all trimmed: its coordinates are stale, another merge can be drawn there now, and the matrix must not hold it (see removeFromMatrix()).

ParamTypeDescription
mergedCellInfoobjectThe merged cell information object. Has to contain row, col, colspan and rowspan properties.

Returns: MergedCellCoords - The new merged cell.

canAdd

Source code

mergedCellsCollection.canAdd(mergedCellInfo, [auto], [ignoredMergedCells]) ⇒ boolean

Checks whether add() would accept a merged cell, and warns as add() does when it overlaps another one. A merge runs it before it touches the cells, so a merge add() would refuse writes no cell meta and leaves no undo step (DEV-159). Both methods decide through the same private check, so a rule cannot reach one of them without the other.

ignoredMergedCells lists merges that the caller removes before it adds this one: mergeSelection() unmerges the merges whose anchor lies inside the range first, and asks here before it touches any of them.

ParamTypeDefaultDescription
mergedCellInfoobjectThe merged cell information object. Has to contain row, col, colspan and rowspan properties.
[auto]booleanfalseoptional true if called internally by the plugin (usually in batch).
[ignoredMergedCells]Array<MergedCellCoords>[]optional Merged cells to treat as already removed.

Returns: boolean - true if add() would add the merged cell.

capturePhysicalSpans

Source code

mergedCellsCollection.capturePhysicalSpans(axis) ⇒ Map<MergedCellCoords, Array<number>>

Capture the physical indexes covered by every merged cell along an axis.

Used by the manual row/column move and column freeze integrations to translate merges through a reorder: the captured spans pin each merge to the underlying data so the merge can be repositioned (and split, if a non-contiguous run results) after the visual sequence changes.

ParamTypeDescription
axis'column'
'row'
Which axis the upcoming reorder targets.

Returns: Map<[MergedCellCoords](/docs/vue-data-grid/api/merged-cell-coords/), Array<number>> - Map of merge -> physical indexes along the axis.

clear

Source code

mergedCellsCollection.clear()

Clear all the merged cells.

detectContiguousRuns

Source code

MergedCellsCollection.detectContiguousRuns(sortedAscending) ⇒ Array<{start: number, length: number}>

Group an ascending list of integers into contiguous runs.

ParamTypeDescription
sortedAscendingArray<number>Already-sorted ascending visual indexes.

dropMerges

Source code

mergedCellsCollection.dropMerges(merges)

Drops a batch of merges from both the mergedCells list and the lookup matrix, matching them by identity rather than by coordinates. A merge that no longer covers any row has visual coordinates that describe nothing, so MergedCellsCollection#remove’s coordinate lookup cannot find it.

ParamTypeDescription
mergesArray<MergedCellCoords>The merges to drop.

filterOverlappingMergeCells

Source code

mergedCellsCollection.filterOverlappingMergeCells(mergedCellsInfo) ⇒ Array<{row: number, col: number, rowspan: number, colspan: number}>

Filters merge cells objects provided by users from overlapping cells. The cells the existing merges occupy are read from the lookup matrix, not the list: a merge whose rows are all trimmed is purged from the matrix and keeps stale coordinates in the list, so it occupies nothing on screen (DEV-3135).

ParamTypeDescription
mergedCellsInfoObjectThe merged cell information object. Has to contain row, col, colspan and rowspan properties.

get

Source code

mergedCellsCollection.get(row, column) ⇒ MergedCellCoords | boolean

Get a merged cell from the container, based on the provided arguments. You can provide either the “starting coordinates” of a merged cell, or any coordinates from the body of the merged cell.

ParamTypeDescription
rownumberRow index.
columnnumberColumn index.

Returns: MergedCellCoords | boolean - Returns a wanted merged cell on success and false on failure.

getBottomMostRowIndex Deprecated

Source code

mergedCellsCollection.getBottomMostRowIndex(range, visualRowIndex) ⇒ number

Gets the bottom-most visual row index that do not intersect with other merged cells within the provided range.
ParamTypeDescription
rangeCellRangeThe range to search within.
visualRowIndexnumberThe visual row index to start the search from.

getByRange

Source code

mergedCellsCollection.getByRange(range) ⇒ MergedCellCoords | false

Get the first-found merged cell containing the provided range.

ParamTypeDescription
rangeCellRangeThe range to search merged cells for.

getByVisualColumn

Source code

mergedCellsCollection.getByVisualColumn(column) ⇒ Array<MergedCellCoords>

Get the merged cells that cover any cell of the provided visual column. The cost scales with the total number of merged cells, not with the number of table rows. Merges purged from the lookup matrix (fully hidden) are not returned.

ParamTypeDescription
columnnumberVisual column index.

Returns: Array<MergedCellCoords> - Array of merged cells covering the column.

getByVisualRow

Source code

mergedCellsCollection.getByVisualRow(row) ⇒ Array<MergedCellCoords>

Get the merged cells that cover any cell of the provided visual row. The cost scales with the number of merged cells covering the row, not with the number of table columns. Merges purged from the lookup matrix (fully hidden) are not returned.

ParamTypeDescription
rownumberVisual row index.

Returns: Array<MergedCellCoords> - Array of merged cells covering the row.

getEndMostColumnIndex Deprecated

Source code

mergedCellsCollection.getEndMostColumnIndex(range, visualColumnIndex) ⇒ number

Gets the end-most visual column index that do not intersect with other merged cells within the provided range.
ParamTypeDescription
rangeCellRangeThe range to search within.
visualColumnIndexnumberThe visual column index to start the search from.

getFirstRenderableCoords

Source code

mergedCellsCollection.getFirstRenderableCoords(row, column) ⇒ CellCoords

Get the first renderable coords of the merged cell at the provided coordinates.

ParamTypeDescription
rownumberVisual row index.
columnnumberVisual column index.

Returns: CellCoords - A CellCoords object with the coordinates to the first renderable cell within the merged cell.

getStartMostColumnIndex Deprecated

Source code

mergedCellsCollection.getStartMostColumnIndex(range, visualColumnIndex) ⇒ number

Gets the start-most visual column index that do not intersect with other merged cells within the provided range.
ParamTypeDescription
rangeCellRangeThe range to search within.
visualColumnIndexnumberThe visual column index to start the search from.

getTopMostRowIndex Deprecated

Source code

mergedCellsCollection.getTopMostRowIndex(range, visualRowIndex) ⇒ number

Gets the top-most visual row index that do not intersect with other merged cells within the provided range.
ParamTypeDescription
rangeCellRangeThe range to search within.
visualRowIndexnumberThe visual row index to start the search from.

getVisibleMergedCells

Source code

mergedCellsCollection.getVisibleMergedCells() ⇒ Array<MergedCellCoords>

Get the merged cells that are not trimmed away: every merge except the ones purged from the lookup matrix because all of their rows are trimmed. A purged merge keeps stale visual coordinates in the mergedCells list, which can point at rows that other records have moved into. A merge whose rows are only hidden is returned, because hidden rows keep their visual index.

Returns: Array<MergedCellCoords> - The visible merged cells, in the order of the mergedCells list.

getWithinRange

Source code

mergedCellsCollection.getWithinRange(range, [countPartials]) ⇒ Array<MergedCellCoords>

Get the merged cells contained in the provided range. Each merged cell is returned once, even when it spans multiple cells of the range. The cost scales with the number of merged cells in the collection, not with the area of the range.

ParamTypeDefaultDescription
rangeCellRangeThe range to search merged cells in.
[countPartials]booleanfalseoptional If set to true, all the merged cells overlapping the range will be taken into calculation.

Returns: Array<MergedCellCoords> - Array of found merged cells, ordered by their first covered cell in row-major order.

IS_OVERLAPPING_WARNING

Source code

MergedCellsCollection.IS_OVERLAPPING_WARNING(mergedCell) ⇒ string

Get a warning message for when the declared merged cell data overlaps already existing merged cells.

ParamTypeDescription
mergedCellObjectObject containing information about the merged cells that was about to be added.

isFirstRenderableMergedCell

Source code

mergedCellsCollection.isFirstRenderableMergedCell(row, column) ⇒ boolean

Check whether the provided row/col coordinates direct to a first not hidden cell within merge area.

ParamTypeDescription
rownumberVisual row index.
columnnumberVisual column index.

isOverlapping

Source code

mergedCellsCollection.isOverlapping(mergedCell, [ignoredMergedCells]) ⇒ boolean

Check if the provided merged cell overlaps with the others already added. Like getWithinRange(), it asks the lookup matrix which merges take up cells: a merge purged from the matrix because all of its rows are trimmed keeps stale visual coordinates and covers no cell on screen.

ParamTypeDefaultDescription
mergedCellMergedCellCoordsThe merged cell to check against all others in the container.
[ignoredMergedCells]Array<MergedCellCoords>[]optional Merged cells to leave out of the check.

Returns: boolean - true if the provided merged cell overlaps with the others, false otherwise.

relocateInMatrix

Source code

mergedCellsCollection.relocateInMatrix(relocations)

Relocates a batch of merges in the coords->merge lookup matrix, applying each merge’s new visual top-left. Used after re-anchoring to the visible rows on a trimming/sort change. Incremental alternative to a full rebuild — only the cells of the affected merges are touched. Runs in two phases (remove all, then re-add all) so merges that swap visual positions don’t clobber each other’s freshly written entries.

ParamTypeDescription
relocationsArray<object>The merges to move together with their new top-left visual row/col and, when rows inside them have been trimmed away, their new visual rowspan.

remove

Source code

mergedCellsCollection.remove(row, column) ⇒ MergedCellCoords | boolean

Remove a merged cell from the container. You can provide either the “starting coordinates” of a merged cell, or any coordinates from the body of the merged cell.

ParamTypeDescription
rownumberRow index.
columnnumberColumn index.

Returns: MergedCellCoords | boolean - Returns the removed merged cell on success and false on failure.

removeFromMatrix

Source code

mergedCellsCollection.removeFromMatrix(merges)

Removes a batch of merges from the coords->merge lookup matrix without touching the mergedCells list. Used to purge merges whose whole visible span has been trimmed away, so their stale entries cannot resolve to a phantom merge once a different row surfaces at the same visual slot. The merges themselves are kept (their physical anchor lets them be re-added when visible).

ParamTypeDescription
mergesArray<MergedCellCoords>The merges to remove from the matrix.

restoreMerges

Source code

mergedCellsCollection.restoreMerges()

Puts existing merges back into the mergedCells list, keeping each object (and so everything the plugin keys on it). The lookup matrix is left untouched: the caller places the merges there itself, from their physical anchors.

shiftCollections

Source code

mergedCellsCollection.shiftCollections(direction, index, count, [canRemove])

Shift the merged cell in the direction and by an offset defined in the arguments.

ParamTypeDescription
directionstringright, left, up or down.
indexnumberIndex where the change, which caused the shifting took place.
countnumberNumber of rows/columns added/removed in the preceding action.
[canRemove]functionoptional Decides whether a merge the shift wants to drop may really be dropped. A merge whose rows are partly trimmed occupies fewer visual rows than it owns, so removing all of its visible rows must not delete the trimmed ones with them. Such a merge is kept with its coordinates left as the shift found them; the caller re-derives them from the merge’s physical rows right after.

translateAfterAxisMove

Source code

mergedCellsCollection.translateAfterAxisMove(axis, snapshot, [retainedIndexes]) ⇒ Map<MergedCellCoords, Array<MergedCellCoords>>

Translate the merged cells collection after a manual row/column reorder, splitting merges whose physical indexes are no longer contiguous in the new visual order.

Note: single-cell fragments (colspan === 1 && rowspan === 1) are dropped because they no longer represent a merge. The user-facing behavior (auto-split + silent drop of singletons) is documented in docs/content/guides/cell-features/merge-cells/merge-cells.md under “Behavior during row/column reorder and column freeze”. The one exception is a fragment the caller lists in retainedIndexes: it shows one cell only because the rest of its rows are trimmed, so it is a merge again as soon as they come back. Both the row and the column callers pass it, since a merge trimmed to one visible row is already rowspan: 1 before any column move.

Every merge is replaced by a new object, so the returned map tells the caller which merges came out of which — the plugin uses it to carry each merge’s physical anchor onto its replacements instead of re-deriving one from the post-move visual coordinates.

ParamTypeDescription
axis'column'
'row'
Axis that was reordered.
snapshotMap<MergedCellCoords, Array<number>>Snapshot taken before the reorder.
[retainedIndexes]Map<MergedCellCoords, Set<number>>optional Per merge, the physical indexes along axis whose single-cell fragment must survive the singleton drop. Keyed per merge because two merges in different columns can cover the same rows, and only one of them may be carrying trimmed rows.

Returns: Map<[MergedCellCoords](/docs/vue-data-grid/api/merged-cell-coords/), Array<[MergedCellCoords](/docs/vue-data-grid/api/merged-cell-coords/)>> - Map of the merge before the reorder -> the merges that replaced it. A merge the reorder dropped entirely maps to an empty array.