fnDraw() after retrieving and appending html rows to an existing dataTable
fnDraw() after retrieving and appending html rows to an existing dataTable
Hi,
I can't manage having a dataTable refresh using fnDraw() after appending html rows retrieved by Ajax. Here is the concerned piece of code :
[code]jQuery.ajax({
type: "POST",
url: url,
data: data,
success: function(trs) {
// Append retrieved rows
var table = jQuery('#table');
table.append(trs);
// Redraw dataTable
var dataTable = table.dataTable();
dataTable.fnDraw();
}
});[/code]
Is this possible ?
Thanks in advance.
I can't manage having a dataTable refresh using fnDraw() after appending html rows retrieved by Ajax. Here is the concerned piece of code :
[code]jQuery.ajax({
type: "POST",
url: url,
data: data,
success: function(trs) {
// Append retrieved rows
var table = jQuery('#table');
table.append(trs);
// Redraw dataTable
var dataTable = table.dataTable();
dataTable.fnDraw();
}
});[/code]
Is this possible ?
Thanks in advance.
This discussion has been closed.
Replies
Allan
Thank you for the answer.
Yes, new rows are well added to the TBODY and follow the empty TR (the one that contains the "dataTables_empty" TD).
However, I should have specify more clearly that, in my case, since rows are retrieved in a raw html format, fnAddData() is not really suitable for my need. I don't want to deal with the data on the client-side because the rows are generated on the server-side (using a form framework).
The only way I see that would do the trick would be to parse the html response and use fnAddData() to regenerate the lines ... Have you perhaps any other more suitable/smarter solution?
In the mean time, if you are only adding data to an empty table, you could use the new fnDestroy API function in 1.7 beta and "kill" the old table, which will put the original html back into place, then add your rows, and re-initialise the table. Bit of a round-about method though... The API function would probably be much cleaner.
Regards,
Allan
Allan