HTML:
<table cellpadding="0" cellspacing="1" border="0" class="display" id="TableId">
<thead>
<tr>
<th>Name</th>
<th>Entry</th>
<th>Exit</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
数据表函数:
$('#TableId').dataTable({
"bProcessing": true,
"bInfo": false,
"sAjaxSource": '/JSON/Path',
"bAutoWidth": false,
"bRetrieve":true
});
JSON:
{"aaData":[ ["Name 1","9516","4851"],
["Name 2","251304","127283"]
]}
我正在尝试在入口和导出之间添加不同的列计算。
如何做到这一点?
最佳答案
您可以使用 fnRowCallback
选项来获取该 . 在标记中添加计算列
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
/* Append the grade to the default row class name */
var diff = aData[1]-aData[2];
$('td:eq(3)', nRow).html(diff);
return nRow;
},
"aoColumnDefs": [ {
"sClass": "center",
"aTargets": [ -1, -2 ]
} ]
关于javascript - DataTable 如何从 JSON 添加列渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5242000/