admin管理员组文章数量:1326012
I am trying to use the Datatables Rows Created Callback to modify the data in the row before drawing it. What I am trying to do is replace all <
and >
with '<'
and '>'
so I can put a line break in each cell and have text on separate lines. '\n'
or linefeed
does not work.
var oTable = $('#table').DataTable( {
"createdRow" : function( row, data, index) {
console.log( 'DATA WAS ' + data[0]);
data[0] = data[0].replace(/</g,'<').replace(/>/g,'>');
console.log( 'DATA IS ' + data[0]);
}
in the console I can see the data being modified correctly. But its not actually modifying the table. Is there a way to do this? or is the createdRow callback called after the row has already been drawn?
I am trying to use the Datatables Rows Created Callback to modify the data in the row before drawing it. What I am trying to do is replace all <
and >
with '<'
and '>'
so I can put a line break in each cell and have text on separate lines. '\n'
or linefeed
does not work.
var oTable = $('#table').DataTable( {
"createdRow" : function( row, data, index) {
console.log( 'DATA WAS ' + data[0]);
data[0] = data[0].replace(/</g,'<').replace(/>/g,'>');
console.log( 'DATA IS ' + data[0]);
}
in the console I can see the data being modified correctly. But its not actually modifying the table. Is there a way to do this? or is the createdRow callback called after the row has already been drawn?
Share edited Jun 14, 2014 at 11:04 Bach 6,2277 gold badges38 silver badges64 bronze badges asked Jun 14, 2014 at 10:53 user1768233user1768233 1,4613 gold badges20 silver badges28 bronze badges2 Answers
Reset to default 4Yep, correct. createdRow callback is only called after the row has already been drawn. Instead of fixing your current code, I will show you how to do it using the proper (?) way by using column defs :D Also, I'd think/hope there was something somewhere that would convert your <
stuff automatically.
var oTable = $('#table').DataTable( {
"columnDefs": [ {
"targets": 0,
"render": function(data, type, row, meta) {
html = data.replace(/</g,'<').replace(/>/g,'>');
return html;
},
],
}
Add the modified element back to the td (column) in question.
var oTable = $('#table').DataTable( {
"createdRow" : function( row, data, index) {
console.log( 'DATA WAS ' + data[0]);
data[0] = data[0].replace(/</g,'<').replace(/>/g,'>');
console.log( 'DATA IS ' + data[0]);
$('td', row).eq(0).append(data[0]);
}
本文标签: javascriptWhy is my jquery datatables createdrow function not workingStack Overflow
版权声明:本文标题:javascript - Why is my jquery datatables createdrow function not working? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742143705a2422694.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论