Skip to content

Instantly share code, notes, and snippets.

@vendettamit
Created July 29, 2013 12:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vendettamit/6103990 to your computer and use it in GitHub Desktop.
Save vendettamit/6103990 to your computer and use it in GitHub Desktop.
Remove rowspan/colspan and split the cells with duplicate values
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