我看到这个链接http://jsfiddle.net/lakshmanakumar/fDCcH/非常有用,我需要再添加一个功能,比如"基于总数排序子组"。 在上面的例子中,我需要按以下顺序显示子组 Job2-24 它的对应行 Job3-21 它的对应行 Job1-11 它的对应行
有人可以帮我完成吗?
$(document).ready(function() {
});
$(function() {
var oTable = $('#job_history').dataTable({
"aoColumnDefs": [{ "bVisible": false, "aTargets": [4, 5, 6]}],
"aLengthMenu": [[10, 25, 50, -1], ["Show 10 entries", "Show 25 entries", "Show 50 entries", "Show all entries"]],
"iDisplayLength": -1,
"aaSortingFixed": [[5, 'asc']],
"aaSorting": [[5, 'asc']],
"bJQueryUI": true,
"sDom": '<flip>',
"fnDrawCallback": function(oSettings) {
if (oSettings.aiDisplay.length == 0) {
return;
}
// GROUP ROWS
var nTrs = $('#job_history tbody tr');
var iColspan = nTrs[0].getElementsByTagName('td').length;
var sLastGroup = "";
for (var i = 0; i < nTrs.length; i++) {
var iDisplayIndex = oSettings._iDisplayStart + i;
var sGroup = oSettings.aoData[oSettings.aiDisplay[iDisplayIndex]]._aData[5];
if (sGroup != sLastGroup) {
var nGroup = document.createElement('tr');
var nCell = document.createElement('td');
nCell.colSpan = iColspan;
nCell.className = "group";
nCell.innerHTML = sGroup;
nGroup.appendChild(nCell);
nTrs[i].parentNode.insertBefore(nGroup, nTrs[i]);
sLastGroup = sGroup;
}
}
// SUM COLUMNS WITHIN GROUPS
var total = 0;
$("#job_history tbody tr").each(function(index) {
if ($(this).find('td:first.group').html()) {
total = 0;
} else {
total = parseFloat(total) + parseFloat(this.cells[4].innerHTML);
$(this).closest('tr').prevAll('tr:has(td.group):first').find("div").html(total);
}
});
}
});
});