Failing to reload datatables with updated information
Failing to reload datatables with updated information
Hi Allan,
I'm working on a project in which I have to update the dataTable after I have performed some record update.
I'm using C# for the backend end I'm getting all json responses properly.
Here is how I go about it, please note that the following code is a minified version of the app I'm working on:
[code]
var oTable,
var otherVars; //global vars
var app = {
getAllData: function() {
return $.ajax({
type: "POST",
url: "/Services/SerialNumberLookupService.aspx/GetSerialWorkOrder",
data: JSON.stringify(serverMethodParamObject),
contentType: "application/json; charset=utf-8",
dataType: "json"
});
},
init: function(config) {
var _self = this,
deferred = $.Deferred();
//some code...
if (typeof oTable !== "undefined" && oTable !== null) {
oTable.fnDestroy();
}
$.when(_self.getAllData()).done(function (resp) {
data = $.parseJSON(resp.d);
if ($('.dataTables_filter').length)
$('.dataTables_filter').remove();
oTable = $('table.dataContainer').dataTable({
aaData: data,
bFilter: true,
bInfo: false,
bPaginate: true,
sPaginationType: "full_numbers",
bJQueryUI: true
});
//some code...
$("#save").on('click', function() {
var _self = this;
_self.init({/*config parm */}); // reloading the dataTable
// more code below
});
};
[/code]
It reloads the data fine the first time, but the second time I get on the console: Uncaught TypeError: Cannot read property 'nTableWrapper' of null line 4557
Thank you for taking the time to response to this.
I'm working on a project in which I have to update the dataTable after I have performed some record update.
I'm using C# for the backend end I'm getting all json responses properly.
Here is how I go about it, please note that the following code is a minified version of the app I'm working on:
[code]
var oTable,
var otherVars; //global vars
var app = {
getAllData: function() {
return $.ajax({
type: "POST",
url: "/Services/SerialNumberLookupService.aspx/GetSerialWorkOrder",
data: JSON.stringify(serverMethodParamObject),
contentType: "application/json; charset=utf-8",
dataType: "json"
});
},
init: function(config) {
var _self = this,
deferred = $.Deferred();
//some code...
if (typeof oTable !== "undefined" && oTable !== null) {
oTable.fnDestroy();
}
$.when(_self.getAllData()).done(function (resp) {
data = $.parseJSON(resp.d);
if ($('.dataTables_filter').length)
$('.dataTables_filter').remove();
oTable = $('table.dataContainer').dataTable({
aaData: data,
bFilter: true,
bInfo: false,
bPaginate: true,
sPaginationType: "full_numbers",
bJQueryUI: true
});
//some code...
$("#save").on('click', function() {
var _self = this;
_self.init({/*config parm */}); // reloading the dataTable
// more code below
});
};
[/code]
It reloads the data fine the first time, but the second time I get on the console: Uncaught TypeError: Cannot read property 'nTableWrapper' of null line 4557
Thank you for taking the time to response to this.
This discussion has been closed.