I have a JQuery Datatables application that I’m trying to load the state from a database with a button click. During the button click event, I retrieve the desired state (oData) from one database table (tblSavedStates), and then I overwrite the state (oData) value in another database table (tblState) which holds the saved state of my web page. Next, I reload the web page and the “stateLoadCallback” function retrieves the new saved state (oData) value from the database. However, I cannot get the “stateSaveCallback” function to save the correct state (the one returned by the “stateLoadCallback” function) into the database. It just saves the current state of the DOM object and not the retrieved state. I’m currently using version 1.10.1 and here’s a snippet of my JQuery code:
// Initialization
var oTable = $('#mytable').dataTable({
"dom": 'RC<"clear">lfrtip',
"processing": true,
"serverSide": true,
"ajax": baseurl + "MyController/IndexAjaxHandler?someId=" + someId,
"sServerMethod": "POST",
"stateSave": true,
"stateSaveCallback": function (oSettings, oData) {
/* Save the oData in the database */
$.ajax({
type: 'POST',
data: { url: $(location).attr('href'), oData: JSON.stringify(oData)},
dataType: "json",
async: false,
url: baseurl + 'MyController/SaveOData',
success: function (data) {
},
error: function () {
}
});
},
"stateLoadCallback": function (oSettings) {
/* Get the oData from the database */
var oData;
$.ajax({
type: 'POST',
async: false,
data: { url: $(location).attr('href') },
url: baseurl + 'MyController /GetOData',
success: function (data) {
oData = data.oData;
},
error: function () {
}
});
/* If returned oData is not an empty string, then parse it */
if (oData != '') {
return JSON.parse(oData);
}
},