How to get sEcho in fnServerData
How to get sEcho in fnServerData
Hi, I am trying to override fnServerData, returning the JSON of my datasource locally like this:
"fnServerData" : function(sSource, aoData, fnCallback){
console.log(collection.toJSON());
fnCallback({
iTotalRecords : collection.length;
iTotalDisplayRecords : collection.length;
aaData : collection.toJSON();
sEcho = ??;
});
However, I don't know how to get the sEcho value, any ideas please? Thanks in advance.
This question has accepted answers - jump to:
Answers
It is available in the
aoData
array. Since you are using the legacy form you need to loop over the array and check the key's in the array to findsEcho
. In the new form you would just be able to dodata.draw
to get the draw counter.Allan
Thanks a lot Allan!
Ok, so just found that aoData contains sEcho along with some other params when "bServerSide" is set to true. aoData is empty when bServerSide is false. A followup question, if I have bServerSide=false, do I need to pass sEcho, iTotalRecords, iTotalDisplayRecords params to fnCallback()? Or is the JSON data is enough for the table to be drawn, with sorting/filtering functionality?
No - they are relevant only for server-side processing.
Allan