ajax.reload() and .row().show()
ajax.reload() and .row().show()

hello,
I have a perfectly working ajax datatable in which with an external button which adds a row after a further ajax post call.
when I call back from this ajax call, I have this:
success: function (response) {
table.ajax.reload();
highlightRow(response.id, table)
},
in which the highlightRow is the well known:
window.highlightRow = function(id, table) {
var row = table.row(function ( idx, data, node ) {
return data.id == id;
} );
if (row.length > 0) {
row.select()
.show()
.draw(false);
}
}
meant to be re-used in many parts.
Now my 2 questions:
1- after the table.ajax.reload the table in the browser is fine, there is the new record: but inside the highlightRow function this new record is missing, why?
2- the row.select().show().draw(false) works ONLY if I comment out the table.ajax.reload, why?
thanks a lot
Replies
obviously my target is: I have so many records, that when I asynchronously add a new row I want to jump there. Thanks again
Maybe use the
callback
parameter of theajax.reload()
API to call the function to show the row. With what you have you are calling the highlightRow function before theajax.reload()
response.Kevin
Or, if your response contains the newly inserted row data use
row.add()
to add the row and eliminate theajax.reload()
.row.add()
returns an API instance of the new row that you can use for row().ahow(), etc.Kevin
thanks a lot kevin!