Created
July 29, 2013 12:32
-
-
Save vendettamit/6103990 to your computer and use it in GitHub Desktop.
Remove rowspan/colspan and split the cells with duplicate values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tempTable = $('#tbl').clone(true); | |
var tableBody = $(tempTable).children(); | |
$(tableBody).children().each(function(index , item){ | |
var currentRow = item; | |
$(currentRow).children().each(function(index1, item1){ | |
if($(item1).attr("rowspan")) | |
{ | |
// copy the cell | |
var item2 = $(item1).clone(true); | |
// Remove rowspan | |
$(item1).removeAttr("rowspan"); | |
$(item2).removeAttr("rowspan"); | |
// last item's index in next row | |
var indexOfLastElement = $(currentRow).next().last().index(); | |
if(indexOfLastElement <= index1) | |
{ | |
$(currentRow).next().append(item2) | |
} | |
else | |
{ | |
// intermediate cell insertion | |
$(item2).insertBefore($(currentRow).next().children().eq(index1)); | |
} | |
} | |
}); | |
console.log(currentRow) | |
}); | |
$('#test').append(tempTable); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment