Sum colum in serverSide (all records)
Sum colum in serverSide (all records)
viperlodz
Posts: 2Questions: 1Answers: 0
Hi,
I have problem with the total sum column in server side using ajax.
In ajax.php I have something like this
$data = array(
"draw" => isset($_GET['draw']) ? intval($_GET['draw']) : 0,
"recordsTotal" => $this->db->GetOne($sql_records_total),
"recordsFiltered" => $this->db->GetOne($sql_records_filtered),
"netPriceSum" => $this->db->GetOne($sql_net_price_sum),
"grossPriceSum" => $this->db->GetOne($sql_gross_price_sum),
"totalPriceSum" => $this->db->GetOne($sql_total_price_sum),
"data" => $output
);
In netPriceSum, grossPriceSum and totalPriceSum I put sum from sql for all records but I don't know how I can show it on the footer.
I have also sum in the current page and it works very well but I don't have any idea to show total sum.
I read all topic in forum and didn't find solution.``
This discussion has been closed.
Answers
My recommendation would be to use
ajax.dataSrc
as a function which you can assign the totals to global variables. IndrawCallback
you can place those totals in the table's footer. Here is an example I created to show this works with server side processing:http://live.datatables.net/sagujiza/1/edit
I don't have any summations from the server side so I'm just getting the recordsTotal object and displaying it in the footer. The same can be done with the sum objects you are returning.
Kevin
Thanks a lot. I'm trying do it for 2 days.
It works perfect.
Hello,
While the static total is processed by the server before drawing, how can dynamic total be calculated on server side and shown on client side (when filtering records or changing the recs on page)?
Thank you
When server side processing is in enabled each draw (sort, search, paging) causes a request to be sent to the server requesting the data for the current page. Your server script would then need to apply the filters, etc as desired when calculating the totals. The server side processing process is described here:
https://datatables.net/manual/server-side
Not sure if this answers your questions.
Kevin
Thank you for your info.
In my case, I run a query which populate a clientdataset, from where I build a data file in a json format.
I think I am not using server side functionality, because I've deleted the data file after dts was populated and after that, I can perform filtering, searching etc, even the file no longer existed.
Being a static file, I cannot figure out how to manipulate data to show correct totals based on the user actions.
Thank you for you patience
Radu
Ok, so you don't have
serverSide: true
in your config?See if this example gets you started for summing client side data:
https://datatables.net/examples/advanced_init/footer_callback.html
Kevin
Thanks a lot!!! It works.