In DataViewsJS, you can merge the adjacent cells in a column holding the same value using the AutoMerge feature. This feature helps present the data in an understandable manner.
Use the following steps to enable AutoMerge in a column.
var columns = [
{
id: 'country',
caption: 'Country',
dataField: 'Country',
width: 180,
allowCellMerging: true,
},
{
id: 'state',
caption: 'State',
dataField: 'State',
width: 120,
allowCellMerging: true,
},
{
id: 'city',
caption: 'City',
dataField: 'City',
width: 120,
allowCellMerging: true,
},
{
id: 'product',
caption: 'Product',
dataField: 'Product',
width: 280,
allowCellMerging: true,
},
{
id: 'detail',
caption: 'Detail',
dataField: 'Product_Detail',
width: '*',
},
];
var grouping = [
{
field: 'country',
header: {
visible: false,
},
footer: {
visible: false,
},
},
{
field: 'state',
header: {
visible: false,
},
footer: {
visible: false,
},
},
];
var dataView = new GC.DataViews.DataView(
document.getElementById('grid1'),
data,
columns,
new GC.DataViews.GridLayout({
allowColumnReorder: false,
allowCellMerging: true,
selectionUnit: 'cell',
grouping: grouping,
})
);
The following settings are available for the AutoMerge feature:
Settings | Property | Description | Example |
---|---|---|---|
Mode | free | Merges the adjacent cells in a column if they have the same values. | |
Mode | restrict | Does not merge the adjacent cells in a column even if they have the same value. | |
Grouped Column | showIcon | Uses special grouping icon for the merged columns. | |
Grouped Column | onlyShowFirstRowValueInEachGroup | Shows the value of merged cell only in the first row. |
Submit and view feedback for