fnRowCallback and fnUpdate
fnRowCallback and fnUpdate
Hi,
is there a a way to force fnRowCallback to be called on both fnUpdate and fnAddData?
As far as I can tell it only gets called on fnAddData.
is there a a way to force fnRowCallback to be called on both fnUpdate and fnAddData?
As far as I can tell it only gets called on fnAddData.
This discussion has been closed.
Replies
Thanks
I never thought of that before... It does make sense though! I'll look into it for the next release, and see if it's a sensible thing to do (which on first glance it is!).
Allan
do you think it could be easy to make the change myself? im not sure how the callback is getting called within fnAddData though.
From my understanding, the row callback function gets called when the table is drawn and not data is added ( unless you redraw each time you add data). If that's the case, doesnt fnUpdate call draw too?
Thanks
Sorry yes - you are quite correct and I'm getting myself confused :-). fnRowCallback is called whenever the row is display (I was thinking of fnRender which is done only when the row is added).
fnUpdate will redraw be default (it can be overridden with a parameter). So assuming your new row is being displayed, it should have the callback function acting on it it. Is it not? Can you link to an example?
Allan
But here's the callback function when the table is initialized
[code]
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
decorateRow(nRow);
return nRow;
}
function decorateRow(row) {
$(row).children().each(function(index, td){
if ($(td).html().indexOf("-") === 0) {
$(td).css("color", "red");
}
else {
$(td).css("color", "");
}
});
}
[/code]
when fnAddData is called, the callback is called.
on fnUpdate(row, rowElem) the callback is not called
It says in the API page that an optional value of redrawing can be used, but default is true.
I've just tried the following code on my zero config page ( http://datatables.net/examples/basic_init/zero_config.html ), and it appears to work as expected for me:
[code]
$(document).ready(function() {
$('#example').dataTable( {
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
decorateRow(nRow);
return nRow;
}
} );
$('#example').dataTable().fnUpdate( ["-","1","2","-","4"], $('#example tbody tr:eq(0)')[0] );
} );
function decorateRow(row) {
$(row).children().each(function(index, td){
if ($(td).html().indexOf("-") === 0) {
$(td).css("color", "red");
}
else {
$(td).css("color", "");
}
});
}
[/code]
Perhaps you could paste in your fnUpdate call?
Allan
my fnUpdate is a simple fnUpdate(row, rowElem) with row being an array of strings ( length is same number as columns) and rowElem is the tr element i want to update.
So I have copied and pasted your code onto a newly created page with 1.6.2 and it doesn't work.
With 1.7 beta it works fine.
so clearly, there must be something in 1.6.2 that prevents the callback from being called on an fnUpdate.
andreas
in 1.7 you have
/* Redraw the table */
if ( typeof bRedraw == 'undefined' || bRedraw )
{
_fnReDraw( oSettings );
}
whereas in 1.6.2 you have
/* Redraw the table */
if ( typeof bRedraw != 'undefined' && bRedraw )
{
_fnReDraw( oSettings );
}
:)
Regards,
Allan
Maybe there is an other issue, at least it was not working as I thought before:
I use a DataTable with a sAjaxSource and now I want to change the contents of one row. After I do that (calling the backend, the backend is updating the row in the database) I want to update the DataTable without reloading all the data from the server because of performance and comfortability reasons. So I call
[code]
var pos = datatable.fnGetPosition(row);
datatable.fnUpdate(data, pos, 0, false, false);
[/code]
But this is not calling fnRowCallback on the specified row (as I expected before). Maybe you could change that, otherwise this is a workaround for all running into the same problem:
[code]
datatable.fnSettings().fnRowCallback(row, data, 0, 0);
[/code]
Greetings,
bruce
Richard
In burce's case above, fnRowCallback was not being called because he's explicitly telling DataTables not to redraw the table (parameter 4 is false) and fnRowCallback is called only when a row is displayed (@bruce - if you read this, sorry I didn't get back to you at this time!). It looks like you are in the same boat with passing false.
Are you using server-side processing? If so, fnUpdate isn't a particularly useful function for you since its client-side only (like fnAddData and fnDeleteRow) - and there isn't any data stored on the client-side - its all on the server, and every draw must make a call to get the latest data.
Perhaps you could explain a bit more about what you are trying to do, and if you can, run your table through the debugger ( http://debug.datatables.net ) so I can see and understand its configuration.
Allan
I'm using server-side processing too. One row looks like this:
[code]row = [
{"track_id":"128","rating":"2"},
"1",
null,
{"track_id":"128"},
"foo.mp3",
{"track_id":"128","rating":"2"}][/code]
During some backend events some of this entries have to be updated. The event contains (along with other data) just the same data like the ajax calls und I want to inject this row into the table (instead of an upgrade of the whole data). And I'm using "fnRender" to convert the above data to HTML strings.
Is there a solution for this combination? Using "server-side processing" and "replacing single rows" with fnRender on client side?
Allan