问题:
因为我不知道/不明白我的选择是什么,所以我想描述一下我理想中想做的事情:
我不明白的部分是如何在表单元元素上创建自定义数据属性。这是可能的还是我需要考虑另一种方法。任何帮助都是非常感谢的!
发布于 2014-10-06 06:56:33
您可以尝试在实例化时使用createdRow回调。示例:
$table.dataTable({
"destroy": true, // To replace existing data
"data": jsonData,
"columns": columns,
// Per-row function to iterate cells
"createdRow": function (row, data, rowIndex) {
// Per-cell function to do whatever needed with cells
$.each($('td', row), function (colIndex) {
// For example, adding data-* attributes to the cell
$(this).attr('data-foo', "bar");
});
}
});我觉得这能帮你做你想做的事。
发布于 2016-10-18 20:11:13
我不得不做一些类似的事情。我不确定剩下的部分,但是我使用columnDefs选项来设置属性。
....
"destroy": true, // To replace existing data
"data": jsonData,
"columns": columns,
// Sets the attribute
"columnDefs": [{
"targets":'_all',
"createdCell": function(td){
td.setAttribute('foo','bar');
}
}]
...它仍然使用createdCell选项,但它模仿了我在他们的文档(https://datatables.net/reference/option/columns.createdCell)中发现的内容。
https://stackoverflow.com/questions/25829824
复制相似问题