When putting datatable inside an ajax callback, how do you access settings?
When putting datatable inside an ajax callback, how do you access settings?
Due to having dynamic column names I am using datatables inside an ajax callback, rather than using datatables' own ajax feature. (This was advised somewhere on this board, though I can't seem to find it now.)
I cannot figure out how to set settings, such as ""serverSide": true", inside the ajax callback, however.
This works (no settings):
$.ajax( {
"url": "get_table.php",
"type": "POST",
"data": {
"s1": series_1,
"s2": series_2,
"s3": series_3,
"t1": topic_1,
"q1": question_1
},
"success": function ( json ) {
$(document).ready(function() {
$('#data_table').dataTable(
json//<<<<<============================= this works!
)
})
},
"dataType": "json"
} );
but my attempts to use settings produce a surprising error:
$.ajax( {
"url": "get_table.php",
"type": "POST",
"data": {
"s1": series_1,
"s2": series_2,
"s3": series_3,
"t1": topic_1,
"q1": question_1
},
"success": function ( json ) {
$(document).ready(function() {
$('#data_table').dataTable(
{
"ajax":json //<<<<<<<========================== this breaks!
}
)
})
},
"dataType": "json"
} );
This throws the error Uncaught TypeError: Cannot read property 'aDataSort' of undefined even though, in the working example, datatables didn't look for aDataSort, even though (as far as I can tell) "aDataSort" is deprecated in favour of "orderData", and even though the json data in question actually contains an aDataSort field anyway.
I've tried a few varieties of "ajax":, such as "sAjaxSource": (deprecated?), and got the same error.
How do I do it?
thanks
John