admin管理员组文章数量:1390718
I am doing some post processing in datatable in fnRowCallback. But they are not being called when the table is redrawn. (i.e, when some event like changing the number of displayed rows are called from UI, the table is redrawn)
$(document).ready(function () {
var oTable = $('#data').dataTable({
"bJQueryUI": true,
"bProcessing": true,
"bServerSide": true,
"bSort": false,
"sAjaxSource": "query.php",
"sPaginationType": "full_numbers",
"aoColumns": [
null,
null,
null,
],
"fnRowCallback": function (nRow, aData, iDisplayIndex) {
$(nRow).attr("id", aData[4]);
return nRow;
},
"fnDrawCallback": function( oSettings ) {
// How do I call fnRowCallback here?
// losing post processing because it is not being called after a redraw
}
});
I am doing some post processing in datatable in fnRowCallback. But they are not being called when the table is redrawn. (i.e, when some event like changing the number of displayed rows are called from UI, the table is redrawn)
$(document).ready(function () {
var oTable = $('#data').dataTable({
"bJQueryUI": true,
"bProcessing": true,
"bServerSide": true,
"bSort": false,
"sAjaxSource": "query.php",
"sPaginationType": "full_numbers",
"aoColumns": [
null,
null,
null,
],
"fnRowCallback": function (nRow, aData, iDisplayIndex) {
$(nRow).attr("id", aData[4]);
return nRow;
},
"fnDrawCallback": function( oSettings ) {
// How do I call fnRowCallback here?
// losing post processing because it is not being called after a redraw
}
});
Share
Improve this question
asked Feb 25, 2014 at 17:21
NEONEO
2,0118 gold badges36 silver badges55 bronze badges
6
- Where is your code that redraws the table? – Justin C Commented Feb 25, 2014 at 17:26
- I don't manually redraw, but the table is redrawn automatically when pagination is used if I am correct. I just want to hook the code I use in rowcallback whenever the table is redrawn. – NEO Commented Feb 25, 2014 at 17:27
-
fnRowCallback
should be called on each row every redraw, maybe try manually redrawing the table and seeing iffnRowCallback
is called. – Justin C Commented Feb 25, 2014 at 17:32 - But how do I manually call redraw if datatable itself calls redraw during pagination or display number of rows change? – NEO Commented Feb 25, 2014 at 17:35
-
I meant call
oTable.fnDraw()
somewhere outside of the callbacks, just to make sure thatfnRowCallback
gets fired on all redraws, not just the initial draw. – Justin C Commented Feb 25, 2014 at 17:37
1 Answer
Reset to default 2I think your attempt to look up the actual row via jquery in $(nRow)
does not work. nRow
contains the whole row. You should just is as namespace for the jquery selector (second parameter) to restrict it to this particular row.
Like so:
$("selector",nRow).jqueryaction()
This works for me:
Html:
<tr>
<td>a</td>
<td class="boldmetight">b</td>
</tr>
<tr>
<td class="boldmetight">c</td>
<td>d</td>
</tr>.. etc
And the table definition with a rowcallback that bolds every cell with a specific class (just for example):
var otable = $("#datatable").dataTable({
"fnRowCallback": function(nRow, aData, iDisplayIndex) {
$('.boldmetight', nRow).html('<b>' + $('.boldmetight', nRow).text() + '</b>');
}
});
Look at this working Plunker
本文标签: javascriptCall fnRowCallback on table redraw in datatableStack Overflow
版权声明:本文标题:javascript - Call fnRowCallback on table redraw in datatable - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744753890a2623344.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论