Skip to content

🔗 Merge Cells

The Cell Merge feature allows you to combine adjacent cells into a single, larger cell, much like Excel’s merge functionality. This feature is particularly useful for creating headers that span multiple columns or rows and for visually grouping related data within your grid.

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

Source code
src/components/cell-merge/CellMerged.ts
import { defineCustomElements } from '@revolist/revogrid/loader';
defineCustomElements(); // Define the custom element
import { useRandomData, currentTheme } from '../composables/useRandomData';
import { CellMergePlugin, ColumnStretchPlugin } from '@revolist/revogrid-pro';
const { isDark } = currentTheme();
const { createRandomData } = useRandomData();
export function load(parentSelector: string) {
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.additionalData = {
cellMerge: [], // Define merge data
stretch: 'all',
};
document.querySelector('.cell-merge')?.addEventListener('click', () => {
grid.additionalData.cellMerge?.push();
grid.additionalData = {
...grid.additionalData,
cellMerge: [{
row: 1,
column: 1,
rowSpan: 2,
colSpan: 2,
rowType: 'rgRow',
colType: 'rgCol',
}],
};
});
grid.theme = isDark() ? 'darkCompact' : 'compact';
grid.hideAttribution = true;
document.querySelector(parentSelector)?.appendChild(grid);
}

Why Use Cell Merge?

Cell Merge is a powerful tool that can help you:

  • Create Merged Headers: Design headers that span across several columns or rows, making it easier to categorize and organize related data.
  • Group Data Visually: Highlight or group related data by merging cells, which improves the readability and interpretability of your grid.

Example Use Cases

  • Merged Headers: Combine cells to create a single header that covers multiple columns. This is ideal for providing overarching categories or labels for grouped columns.
  • Data Grouping: Use cell merging to visually segment related data or to emphasize specific sections of your grid.

How It Works

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.