我敢肯定这是超级hacky,但我可以设置它的唯一方法是创建一个动态的多级手风琴,每个手风琴都嵌套一个dataTable,实际上是在手风琴激活中嵌套dataTable初始化(在表的级别),然后将表 div 标记为已初始化,以便可以重新打开它。这是我的js代码:
$(document).ready(function(){
$(function() {
$('.accordion.second-level').bind('accordionactivate', function (event, ui) {
if (ui.newPanel.length) {
thisPanel = ('#'+ ui.newPanel.attr('id'));
if ($(thisPanel).hasClass('not_activated')) {
$(thisPanel + ' .dataTables_types').dataTable({
"bAutoWidth": false,
"bPaginate": false,
"bScrollCollapse": true,
"sScrollY": "295px",
"aaSorting": [[ 1, "desc" ]],
"sDom": "<'row'<'span10'f>>t<'row'<'span10'i>>",
"aoColumns": [
{ "bSortable": false },
null,
null,
{ "iDataSort": 4 },
{'bVisible': false},
{'bVisible': false},
null
],
"fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
/* Calculate the total transactions on this page */
var total = 0;
for ( var i=iStart ; i<iEnd ; i++ )
{
total += aaData[ aiDisplay[i] ][5]* 1;
}
var nCells = nRow.getElementsByTagName('th');
nCells[1].innerHTML = total;
$(nCells[1]).formatCurrency({negativeFormat:'%s-%n'});
}
});
$(thisPanel).removeClass('not_activated');
}
}
});
});
});
我仍然很想知道是否有更好/更有效的方法来做到这一点,但这确实有效。