我知道这里有一个类似的问题JQuery DataTables: How to show/hide row details with multiple tables? 但这并不完全适用于我当前的问题。
我有代码:
var oTable = $('.dataTable').dataTable( {
"aoColumnDefs": [
{ "bSortable": false, "aTargets": [ 0,3,4 ] },
{ "bVisible": false, "aTargets": [ 4 ] }
],
"aoColumns": [
null,
null,
null,
null,
{ "sType": "html" }
],
"aaSorting": [[1, 'asc']],
"bFilter": false,
"bPaginate": false,
"fnInitComplete": function(oSettings) {
/* Add event listener for opening and closing details
* Note that the indicator for showing which row is open is not controlled by DataTables,
* rather it is done here
*/
$('.dataTable tbody td img').live('click', function () {
var nTr = this.parentNode.parentNode;
if (oTable.fnIsOpen(nTr)) {
// This row is already open - close it
this.src = "css/images/details_open.png";
oTable.fnClose(nTr);
} else {
// Open this row
this.src = "css/images/details_close.png";
oTable.fnOpen(nTr, fnFormatDetails(oTable, nTr), 'details');
}
} );
}
});
如果我将 dataTable 类添加到第二个表中只有一个,那么它们可以作为数据表工作,但显示/隐藏按钮在两个表中都失败。两个表具有相同的字段和内容计数,只是为了使其工作,但仍然没有成功。
在类似的帖子中,该人建议添加:
tbl = $(this).parent().parent().dataTable();
到点击功能,但我试过了,它没有用。
我错过了什么??