我使用此代码是为了通过数据表的 fnCreatedRow 回调在每个原始行下添加额外的行。原始行已正确更新,但附加行在回调后被删除...
fnCreatedRow: function(nRow, aData, iDataIndex) {
var $nRow = $(nRow),
$content = $(),
numIndex = 3;
$nRow.find('td').eq(3).html('');
// We add one or multiple sub rows under each row in order to show the accounts details of the client
$.each(aData[3][0], function(e, i) {
if (e === 'profileId') {
return true;
}
$content = $content.add($nRow.clone().find('td').eq(numIndex).html(i).end().end());
++numIndex;
});
$nRow.after($('<tr>').append($content).html());
}
有更合适的回调吗? 我认为如果我在创建整个表后执行这些操作,但如果插件执行循环...为什么不使用它呢?
我不是唯一遇到此问题的人: https://datatables.net/forums/discussion/21354/using-fncreatedrow-to-add-detail-rows-working-but-not
我想补充一点,我检索的 json 包含第四列的数组。我使用这个数组来构造这些子行。我认为它不起作用,因为数据表需要一个数组或与字符串不同的东西。
最佳答案
我建议考虑使用 row.child() 附加您的子行,就像本示例中所做的那样:
https://datatables.net/examples/api/row_details.html
但是,该示例确实有所不同,因为它们通过单击事件呈现详细信息行 - 然而它们的呈现方式可能是解决问题的关键,而不是使用 $content.add。
关于javascript - 数据表 - 使用 fnCreatedRow 添加详细信息行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33871984/