$(document).ready(function () {
$('#example').dataTable();
MergeGridCells();
});
function MergeGridCells() {
var dimension_cells = new Array();
var dimension_col = null;
var columnCount = $("#example tr:first th").length;
for (dimension_col = 0; dimension_col < columnCount; dimension_col++) {
// first_instance holds the first instance of identical td
var first_instance = null;
var rowspan = 1;
// iterate through rows
$("#example").find('tr').each(function () {
// find the td of the correct column (determined by the dimension_col set above)
var dimension_td = $(this).find('td:nth-child(' + dimension_col + ')');
if (first_instance == null) {
// must be the first row
first_instance = dimension_td;
} else if (dimension_td.text() == first_instance.text()) {
// the current td is identical to the previous
// remove the current td
dimension_td.remove();
++rowspan;
// increment the rowspan attribute of the first instance
first_instance.attr('rowspan', rowspan);
} else {
// this cell is different from the last
first_instance = dimension_td;
rowspan = 1;
}
});
}
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.