If I understand what you mean here, this is my edited version: http://jsfiddle.net/djhU7/4/
So instead of $(this).text('') I did this:
$($this.parent().prev().children()[index]).attr('rowspan', 2); $this.hide();
What I did was I set the rowspan first cell to 2. This attribute "will indicate how many lines the cell is expanding." which doubles the aforementioned cell, and I hid the cell with duplicate information so that the extra cell disappears. Note that deleting a cell will destroy the index check for the next cell. It was a quick and dirty solution, but to achieve it, you must use the rowspan attribute.
Here is another version that sets the spacing between rows when inserting cells into a table, in addition to working with 3 or more duplicate cells, it is also faster because it avoids re-rendering the table (although it can be optimized more, but I donβt think that at the moment you want to take care of this, premature optimization is the root of all evil!): http://jsfiddle.net/g7uY9/1/
for (var i = 0; i < obj.length; i++) { tr = $('<tr/>'); addColumn(tr, 'columnA', i); addColumn(tr, 'columnB', i); addColumn(tr, 'columnC', i); $('#testTable').append(tr); } function addColumn(tr, column, i) { var row = obj[i], prevRow = obj[i - 1], td = $('<td>' + row[column] + '</td>'); if (prevRow && row[column] === prevRow[column]) { td.hide(); } else { var rowspan = 1; for (var j = i; j < obj.length - 1; j++) { if (obj[j][column] === obj[j + 1][column]) { rowspan++; } else { break; } } td.attr('rowspan', rowspan); } tr.append(td); }
source share