admin管理员组文章数量:1334799
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?
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?
Share Improve this question edited Jan 12, 2013 at 2:36 dreamcrash 51.7k26 gold badges111 silver badges132 bronze badges asked Jan 11, 2013 at 20:59 chrischris 37k53 gold badges147 silver badges256 bronze badges2 Answers
Reset to default 3I think you could acplish this by controlling the column definitions and assigning the class via fnRender. After your columns are defined, feed the fnAddData function some data.
Here is a similar SO questions.. CLICK HERE that I think you would find useful.
In your case, I think that the column definitions would look something like this
...
"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>';
}
}
],
...
Via their api .. http://www.datatables/api ... You could feed the table any number of rows via json
var json = eval("[" + response + "]");
oTable.fnAddData(json);
and let the datatable render any formatting itself dynamically
For your first question, you can hook up to the "fnCreatedRow" callback, http://www.datatables/usage/callbacks. This will allow you to listen to row add events and manipulate them as necessary.
The "bonus" is that you can pass 2d-arrays to fnAddData to avoid looping
本文标签:
版权声明:本文标题:javascript - datatables dynamically add row with fnAddData or similar and add a class to a specific column - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742343378a2457038.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论