fnReloadAjax in 1.10.0-dev
fnReloadAjax in 1.10.0-dev
I need to reload the new data into a table via Ajax request.
[code]oTable.fnReloadAjax(null, function () {
alert("Ok.");
});[/code]
This code work fine in 1.9.4, but in 1.10.0-dev i get exception "Object does not support property or method "_fnServerParams"" in fnReloadAjax.js in line 35 "this.oApi._fnServerParams( oSettings, aData );". I could not find a solution to this problem. Maybe in the new version this feature is already built in?
[code]oTable.fnReloadAjax(null, function () {
alert("Ok.");
});[/code]
This code work fine in 1.9.4, but in 1.10.0-dev i get exception "Object does not support property or method "_fnServerParams"" in fnReloadAjax.js in line 35 "this.oApi._fnServerParams( oSettings, aData );". I could not find a solution to this problem. Maybe in the new version this feature is already built in?
This discussion has been closed.
Replies
[code]
var table = $('#example').DataTable(); // NOTE the capital D - this gets an API instance rather than jQuery
table.ajax.reload();
[/code]
The API file for the Ajax options in DataTables 1.10 is here: https://github.com/DataTables/DataTablesSrc/blob/1_10_wip/js/api/api.ajax.js
Allan
The new API provides everything of the old, and more so you shouldn't need the old API at all. Of course it isn't documented yet, so you might want the old API... For data - you can simply use `table.row( selector ).data()` for example, rather than fnGetData. Overall the new API should be much easier to use.
Allan
[code]var oTable = $('#test').dataTable();
oTable.DataTable().ajax.reload();[/code]
It works for me, but would not that be a problem?
And thanks again for your help in my understanding of the new version.
[code]"fnServerData": function (sSource, aoData, fnCallback) {
$.ajax({
success: function (json) {
fnCallback(json);
alert("Ok");
},
error: function (jqXHR, textStatus, errorThrown) {
alert("Error: " + jqXHR.responseText);
}
});
}[/code]
Yes that will work - but you'd be better using:
[code]
oTable.api().ajax.reload();
[/code]
I think. It will just save a few clock cycles.
Regarding the callback - that's a good point. You could do:
[code]
table
.one( 'xhr', function () { ... } )
.ajax.reload();
[/code]
where the `xhr` event handler is the callback.
I'll look at adding this in explicitly.
Allan
Allan