How to get sEcho in fnServerData

How to get sEcho in fnServerData

junaedjunaed Posts: 18Questions: 7Answers: 0

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

  • allanallan Posts: 63,747Questions: 1Answers: 10,509 Site admin
    Answer ✓

    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 find sEcho. In the new form you would just be able to do data.draw to get the draw counter.

    Allan

  • junaedjunaed Posts: 18Questions: 7Answers: 0

    Thanks a lot Allan!

  • junaedjunaed Posts: 18Questions: 7Answers: 0

    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?

  • allanallan Posts: 63,747Questions: 1Answers: 10,509 Site admin
    Answer ✓

    if I have bServerSide=false, do I need to pass sEcho, iTotalRecords, iTotalDisplayRecords params to fnCallback()

    No - they are relevant only for server-side processing.

    Allan

This discussion has been closed.