datatables - Append Row in createRow Event
问题描述
With jquery Datatable, I am trying to add new row in createdRow Event but it not adding.
Anything wrong here?
$("test").DataTable({
"createdRow": function (row, data, dataIndex) {
$(row).after("<tr><td>test</td></tr>");
}
});
解决方案
我可能会假设当节点准备好但未插入到 DOMcreatedRow
时调用回调,因此实际上并不知道 this 所指的位置。row
.after()
当我试图用一些东西来欺骗 DataTable 时,比如:
createdRow: row => {
let newRowTemplate = document.createElement('template');
newRowTemplate.innerHTML = `${row.innerHTML}<tr><td>test</td></tr>`;
row = newRowTemplate.content.children;
}
我也没有成功,因为 DataTable 可能会firstChild
从 HTMLCollection 中过滤掉,所以我看不到<tr>
这个回调抛出 2x 节点的方式。
我可能想到的解决方法是使用row().child()
,它会给你你期望的输出:
createdRow: (row, data, dataIndex) => {
$('#test').DataTable().row(dataIndex).child('<tr><td>test</td></tr>').show();
}
推荐阅读
- git - ~/.ssh/config 正在导入
- python - AttributeError:“str”对象没有属性“configure”
- excel - 连续单元格的VBA部分匹配(值/字符串)
- javascript - 使用 Jquery 上下循环遍历 div
- android - Android 和 Windows 之间的 Socket 通信
- javascript - 如何切片特定的字符串?
- java - 从 java 应用程序连接到 kubernetes pod
- spring-cloud-sleuth - 有没有办法重命名traceId和spanId?
- python - 在Python中从列表中提取匹配的子字符串到新列表
- python - 如何在 google colab 中读取 .docx 文件?