Ok I am trying to dynamically add new rows to a already rendered table using datatables. Thus far what I have is
oTable.fnAddData(["D:\Exlab", '[<a href="#" class="datasource_row_edit" data-idr="reference">Edit</a>] [<a href="#" class="datasource_row_delete" data-idr="reference">Delete</a>]']);
Which this works for adding a single row (if anyone knows how to use a similar function to add multiple rows without running a loop that would be bonus). However I want to have a specific column in this case the second column have a special class, is there a means of adding a class to a column thats being added on the fly?
我想你可以通过控制列定义,并通过fnRender分配类实现这一点。 您的列被定义后,喂fnAddData功能的一些数据。
下面是相似的,所以问题.. 点击这里 ,我想你会发现有用的。
在你的情况,我认为列定义会是这个样子
...
"aoColumns": [
{
"sClass": "datasource_row_edit",
"fnRender": function( oObj ) {
return '<a href="#" data-idr="reference">Edit</a>';
}
},
{
"sClass": "datasource_row_delete",
"fnRender": function( oObj ) {
return '<a href="#" data-idr="reference">Delete</a>';
}
}
],
...
通过他们的API .. http://www.datatables.net/api ......你可以通过JSON提要表中的任何数量的行
var json = eval("[" + response + "]");
oTable.fnAddData(json);
并让数据表提供任何格式本身动态
关于第一个问题,你可以连接到“fnCreatedRow”回调, http://www.datatables.net/usage/callbacks 。 这将允许你听行添加事件,并在必要时对其进行操作。
该“红利”是,你可以通过二维阵列fnAddData避免循环
文章来源: datatables dynamically add row with fnAddData or similar and add a class to a specific column