Handling JSON or counting tags
Handling JSON or counting tags
I am trying to count the number of occurrences that a certain code shows up in a particular column in my dataTable, powered by AJAX.
I suppose there are two ways to go about it.
1) I can add another JSON element with my sEcho, iTotalRecords, iTotalDisplayRecords, aaData, and call it .... myCountCode.
2) I can develop some client side JS to count it after every AJAX request.
The problem is that I don't know how to go about either one on the client side. Could someone show me the way in JS?
This question has an accepted answers - jump to answer
Answers
You could take a look at the footer callback example.
The only disadvantage of doing it client-side (when using server-side processing, as I presume you are based on your mention of
sEcho
etc), is that the client-side will see only the current page of data of course (since that is the whole point of server-side processing). So it will only be able to count occurrences on that page, not the full data set.Allan
I had some trouble understanding .reduce(), trying to figure out what that is, so seeing how I already use the legacy code, I tried its legacy counterpart and it worked.
Thanks.