【发布时间】:2017-05-07 10:34:23
【问题描述】:
这是我第一次使用数据表,我正在逐渐习惯它。
我找到了一种方便的方法来传递附加属性或修改从服务器检索的源数据(我使用来自服务器和客户端渲染的 json 播种)。
代码:
"columnDefs": [{
"targets": "_all",
"createdCell": function (td, cellData, rowData, rowIndex, colIndex) {
//code column
if (colIndex == 0) {
cellData = '<input value="' + cellData + '">';
$(td).html(cellData);
}
//expire column
if (colIndex == 3) {
$(td).html('4');
}
// colouring all columns with index less than 3 as red
if (colIndex < 3) {
$(td).css('color', 'red')
}
}
}]
我觉得有点脏,因为我使用索引来区分数据。
以后我需要为这样的代码还清吗?会有什么后果吗?
是否有任何适当且同时舒适的方式来达到相同的目标?
我还注意到“createdRow”属性,并以与使用 createdCell 相同的方式使用它
【问题讨论】:
标签: javascript jquery datatables