Displaying custom record count, using server side processing
Displaying custom record count, using server side processing
I have a table and one column displays the status of a record
Booked or Available.
I am using server side processing and want to display how many records of the total are booked status and how many are available status.
I have successfully gotten server side filters to work well. I can narrow down my database and only see what I want, but of the full set returned of the filtered data, I would like to be able to display how many are booked and how many are still available.
Is this possible?
(Note, I have gotten this to work like this
"
var available = table.rows().eq( 0 ).filter( function (rowIdx) {
return table.cell( rowIdx, 3 ).data() == 'Available' ? true : false;
} );
document.getElementById("availableallotments").innerHTML = table.rows(available).count();
"
But it only counts the records that are dispalyed on screen, not what is on subsequent pages as I am limiting 50 records to be displayed at a time.
Thank you for your assistance.
This question has an accepted answers - jump to answer
Answers
I should have Summarized.
With server size processing on and paging, I want to perform counts on the full row set returned. Counting how many rows meet each criteria and then display that amount to the user.
You will need to do the calculations server side and pass the data back in a different object, for example:
Using
xhr
you can use thejson
parameter to access the additional data objects you return and display them how you wish.Kevin
Thank you Kevin,
I appreciate the feedback and direction.
Is there a help document that would push me in the right direction regarding how to put a different object into the json returned from the server?
It depends on what you are using on the server-side. Is it a script you've written, a library we publish or is it from somewhere else?
Allan
Thanks for the follow up Allan,
I am using PHP server side,
Here is a sample of what I am using to display that view:
Thank you Kevin and Allan for your help so far and being here to assist.
Super - thank you.
Rather than using the
->json()
method, call->data()
. The json method is basically just the same as:e.g. you might use:
So just before that last line you can add extra information onto the
$data
object:Allan
Amazing,
Thank you Allan, I greatly appreciate your help and this wonderful tool.
Cheers.
Just wanting to update this post with how I ended up performing this for anyone that may look for an answer similar to this.
My Modal providing the JSON data back and forth
Used $data to hold the editor
Then set some variables to hold my counts (which get them from another function
My count function just runs some SQL statements to pull the data how I want and then passing it back.
Thanks Allan and Kevin for your help!
Excellent, thanks for posting back,
Colin