Skip to content

Merge Cells

The Cell Merge feature allows you to combine adjacent body or pinned data cells into a single, larger cell, much like Excel’s merge functionality. Use it to visually group related data within your grid.

For spreadsheet-style headers that span multiple rows or columns, use the Multi Row Headers plugin instead.

const cellMerge = [{ row: 1, column: 1, rowSpan: 2, colSpan: 2, rowType: 'rgRow', colType: 'rgCol' }]

Source code
src/components/cell-merge/CellMerged.ts
import { controlAttributes, createControl } from '@revolist/ui';
import { defineCustomElements } from '@revolist/revogrid/loader';
defineCustomElements(); // Define the custom element
import { useRandomData, currentTheme } from '../composables/useRandomData';
import './CellMerged.css';
import {
CellMergePlugin,
ColumnStretchPlugin,
type MergeData,
} from '@revolist/revogrid-pro';
const { isDark } = currentTheme();
const { createRandomData } = useRandomData();
const initialCellMerge: MergeData[] = [
{
row: 1,
column: 0,
rowSpan: 3,
colSpan: 1,
rowType: 'rgRow',
colType: 'rgCol',
},
];
const mergedCell: MergeData = {
row: 1,
column: 1,
rowSpan: 2,
colSpan: 2,
rowType: 'rgRow',
colType: 'rgCol',
};
export function load(parentSelector: string) {
const parent = document.querySelector(parentSelector);
if (!parent) {
return;
}
parent.classList.add('cell-merge-example');
if (isDark()) {
parent.classList.add('cell-merge-example--dark');
} else {
parent.classList.remove('cell-merge-example--dark');
}
const button = createControl(document, 'button');
button.className = controlAttributes('button', {
class: 'rv-btn mb-2 self-start',
}).class;
button.textContent = 'Merge Cell';
const lineBreak = document.createElement('br');
const grid = document.createElement('revo-grid');
grid.source = createRandomData(100);
// Define columns
grid.columns = [
{
name: 'πŸ†” ID',
prop: 'id',
},
{
name: '🍎 Fruit',
prop: 'name',
},
{
name: 'πŸ’° Price',
prop: 'price',
},
];
// Define plugin
grid.plugins = [CellMergePlugin, ColumnStretchPlugin];
grid.stretch = 'all';
grid.cellMerge = initialCellMerge;
button.addEventListener('click', () => {
grid.cellMerge = [mergedCell];
});
grid.theme = isDark() ? 'darkMaterial' : 'material';
grid.hideAttribution = true;
parent.append(button, lineBreak, grid);
}

Cell Merge is a powerful tool that can help you:

  • Group Data Visually: Highlight or group related data by merging cells, which improves the readability and interpretability of your grid.
  • Data Grouping: Use cell merging to visually segment related data or to emphasize specific sections of your grid.

The Cell Merge feature enables you to specify which cells should be merged into a larger cell. This larger cell will span across multiple columns and/or rows. The content of the merged cell will be centrally displayed, enhancing the layout of your grid.

Since this is a Pro feature, ensure that you have access to the Pro version of RevoGrid to utilize this functionality.