stateSaveCallback called on loading the page
stateSaveCallback called on loading the page
atlaz
Posts: 2Questions: 1Answers: 0
Hi,
I am trying to save and load my state from a database (I am using ajax to save the data). When I load the page it calls the StateLoadCallback first and right after the stateSaveCallback. This results in my old state being loaded from the database and then the default state is saved to the database straight away.
I am sure that I am somehow missunderstanding the use of stateSaveCallback and stateLoadCallback. Could you help me on the way?
Here's my code:
<script>
$(document).ready(function() {
$('.table').dataTable({
"sDom": "Zlfrtip",
"oSelectorOpts": {
filter: "applied"
},
"paging": false,
"stateSave": true,
"stateLoadCallback": function (settings) {
var o;
$.ajax( {
"url": "/sales/stateload",
"async": false,
"dataType": "json",
"success": function (json) {
o = json;
}
} );
return o;
},
"stateSaveCallback": function (settings, data) {
$.ajax( {
"url": "/sales/statesave",
"data":{ "datski":data},
"dataType": "json",
"type": "POST",
"success": function () {}
} );
},
"oTableTools": {
"sSwfPath": "/swf/copy_csv_xls_pdf.swf",
"aButtons": [
{
"sExtends": "copy",
"oSelectorOpts": { filter: 'applied', order: 'current' }
},
{
"sExtends": "xls",
"oSelectorOpts": { filter: 'applied', order: 'current' },
"sFileName": "Testlist-MM-dd_hh.mm.ss.xls"
},
{
"sExtends": "pdf",
"oSelectorOpts": { filter: 'applied', order: 'current' },
"sFileName": "Testlist-MM-dd_hh.mm.ss.pdf",
"sPdfOrientation": "landscape",
"sPdfMessage": "Test List" + ($('div.dataTables_filter input').length > 0 ? " Filter: " + $('div.dataTables_filter input').val() : "")
},
{
"sExtends": "print",
"oSelectorOpts": { filter: 'applied', order: 'current' },
}
]
}
});
});
</script>
This discussion has been closed.
Answers
Nevermind, i dun goofed.
The data returned in the load was faulty.