Request data without rendering
Request data without rendering
If there is nice clean solution to fetch data from server (that supports api) without actual rendering of the table.
In my case I even have no table at all. I just need JSON back.
What works for me is:
[code]
var settings = {
"aoColumns" : [
{ "mDataProp" : "text"}
]
};
var dt = window.dt = $.fn.dataTable(settings);
settings = dt.dataTableSettings[0];
var parameters = dt.oApi._fnAjaxParameters(settings);
$.ajax({
"dataType" : 'json',
"type" : "POST",
"url" : "/json/dataTables/dataTableService",
"data" : parameters,
"success" : function () {
console.info("SUCCESS:", Array.prototype.slice.call(arguments));
},
"error" : function (jqXHR, textStatus, errorThrown) {
console.error("ERROR:", Array.prototype.slice.call(arguments));
}
});
[/code]
In my case I even have no table at all. I just need JSON back.
What works for me is:
[code]
var settings = {
"aoColumns" : [
{ "mDataProp" : "text"}
]
};
var dt = window.dt = $.fn.dataTable(settings);
settings = dt.dataTableSettings[0];
var parameters = dt.oApi._fnAjaxParameters(settings);
$.ajax({
"dataType" : 'json',
"type" : "POST",
"url" : "/json/dataTables/dataTableService",
"data" : parameters,
"success" : function () {
console.info("SUCCESS:", Array.prototype.slice.call(arguments));
},
"error" : function (jqXHR, textStatus, errorThrown) {
console.error("ERROR:", Array.prototype.slice.call(arguments));
}
});
[/code]
This discussion has been closed.
Replies
Yes, just make an Ajax call to the server and get the data :-). Looks like you've got what is needed from line 9 onwards. However, if you need to pass the DataTables parameters - when what you've got is probably about as clean as it gets, since DataTables expects to do a draw on its own Ajax request.
Allan
Using $.fn.dataTable and $(...).dataTable I was failed to override "fnServerData" passed in settings.