$(document).ready(function () {
var anOpen = [];
var oTable = $('#table_id').dataTable();
$('#table_id tbody').on('click', 'tr', function (e) {
var nTr = this.parentNode;
var i = $.inArray(nTr, anOpen);
console.log("clicked|" + i);
if (i == -1) {
var nDetailsRow = oTable.fnOpen(nTr, fnFormatDetails(oTable, nTr), 'details');
$('div.innerDetails', nDetailsRow).slideDown();
anOpen.push(nTr);
console.log("open");
}
else {
oTable.fnClose( nTr );
anOpen.splice( i, 1 );
console.log("closed");
}
});
function fnFormatDetails(oTable, nTr) {
var oData = oTable.fnGetData(nTr);
var sOut =
'<div class="innerDetails">' +
'<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">' +
'<tr><td>Rendering engine:</td><td>' + 'hi' + '</td></tr>' +
'<tr><td>Browser:</td><td>' + 'hi' + '</td></tr>' +
'<tr><td>Platform:</td><td>' + 'hi' + '</td></tr>' +
'<tr><td>Version:</td><td>' + 'hi' + '</td></tr>' +
'<tr><td>Grade:</td><td>' + 'hi' + '</td></tr>' +
'</table>' +
'</div>';
return sOut;
}
刚刚给出了它的一部分,当我点击该行时它会触发if(i == - 1),然后当我再次点击它触发其他并来回工作时问题是我无法得到要展示的任何东西这张桌子就坐下了,新的打开了另一张桌子,就像它应该的那样。控制台中没有错误只是正确的控制台日志。