stateLoadCallback not loading state from DB
stateLoadCallback not loading state from DB
I'm trying to implement stateLoadCallback server side, however it is not loading table state from my DB. Meanwhile stateSaveCallback is working just fine and I can save state in DB.
In my http://localhost:3000/en/common/datatables_states/campaigns_index.json I can get this:
{
"time": "1495083187785",
"start": "0",
"length": "10",
"order": {
"0": [
"0",
"asc"
]
},
"search": {
"search": "",
"smart": "true",
"regex": "false",
"caseInsensitive": "true"
},
"columns": {
"0": {
"visible": "true",
"search": {
"search": "",
"smart": "true",
"regex": "false",
"caseInsensitive": "true"
}
},
"1": {
"visible": "true",
"search": {
"search": "",
"smart": "true",
"regex": "false",
"caseInsensitive": "true"
}
},
"2": {
"visible": "true",
"search": {
"search": "",
"smart": "true",
"regex": "false",
"caseInsensitive": "true"
}
}
}
}
My JS looks like this:
jQuery(document).ready(function() {
var user_id = $("#data-table").attr('data-user-id');
var contname = $("#data-table").attr('data-controller-name');
$('#data-table').DataTable(
{
"processing": true,
"serverSide": true,
"ajax": $('#data-table').data('source'),
"stateSave": true,
"stateSaveCallback": function (settings, data) {
// Send an Ajax request to the server with the state object
$.ajax( {
"url": "/common/datatables_states/"+contname+".json",
"data": {"common_datatable_state":{"user_id": user_id, "name": contname, "state": data}} ,
"dataType": "json",
"method": "PATCH",
"success": function () {}
} );
},
stateLoadCallback: function (settings, callback) {
$.ajax( {
url: "/common/datatables_states/"+contname+".json",
async: false,
dataType: "json",
method: 'GET',
success: function (json) {
callback( json );
}
} );
}
}
);
});
In my Network Monitor I can clearly see XHR GET response with my JSON, however Datatables is not responding and state is not populated. Here is link to my Debug.
How do I fix this, please? I'll be happy for any hint. Thank you!