Request data without rendering

Request data without rendering

mupincmupinc Posts: 2Questions: 0Answers: 0
edited September 2012 in General
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]

Replies

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    > If there is nice clean solution to fetch data from server (that supports api) without actual rendering of the table.

    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
  • mupincmupinc Posts: 2Questions: 0Answers: 0
    My code is "hack" but not nice :) because making just Ajax call I should pass all params by hand, and not forget about echos.
    Using $.fn.dataTable and $(...).dataTable I was failed to override "fnServerData" passed in settings.
This discussion has been closed.