I have the classical table with expandable and collapsible records that if expanded show several subrecords (as new records in the same parent table, not some child div/chil
I was able to overcome this by assigning child rel attributes to children and parent rel attributes to parents. Then I loop through the table at the beginning and hide all of the children and reappend them after the sorting is completed. I also use a toggling function to display the children. Here is my solution:
function lfDisplayProductInformation(id){
if($(`[rel="child-${id}"]`).attr("hidden") === 'hidden'){
$(`[rel="child-${id}"]`).removeAttr('hidden')
}
else if(!$(`[rel="child-${id}`).attr("hidden")){
$(`[rel="child-${id}"]`).attr("hidden", true)
}
}
$(".tablesort")
.tablesorter({
theme: 'blue',
showProcessing : true
})
// assign the sortStart event
.bind("sortStart",function(e, t) {
$("tr[rel^='parent']").each(function() {
var parentRow = $(this);
var tag = (parentRow.attr('rel')).split("-")[1];
var childRow = $(`tr[rel="child-${tag}"]`)
if(!childRow.attr("hidden")){
childRow.attr("hidden", true)
}
});
})
.bind("sortEnd",function(e, t) {
$("tr[rel^='parent']").each(function() {
var parentRow = $(this);
var tag = (parentRow.attr('rel')).split("-")[1];
var childRow = $(`tr[rel="child-${tag}"]`)
childRow
parentRow.after(childRow);
});
})