How to make a sum of the data filtered
How to make a sum of the data filtered
fmarguerie
Posts: 36Questions: 3Answers: 0
Hi,
I have for exemple 3000 rows in my table, i, I filter them, using the filter zone, I get for example;
Page x on 6 pages / 150 records (10 records per page)
I used the sum plug in to compute my sum, but it computes the 3000 rows in any case.
I just want the total of the 150 records filtered (don't care if 10 or 25 or 100 records per page)
I want the whole sum filtered
Is it possible ?
Regards,
François
Replies
cf : http://live.datatables.net/yijufoqa/1
If I enter **New **in the filter zone, to get the 11 records for New-york, the sum is 248650 !
I want the total for new york only ( enven if the display is on 2 pages because of 10 records per page)
Use the
selector-modifier
ofsearch:'applied'
. Similar to this example.Kevin
Hi, thanks, look s great, and close of my request, in the example you sent me, if we filter London => 12 results
I wish to get the sum of the 12 results either we are on 10 records per page (then we get 2 pages) or 25 records per page (then one page is enough)
Hope my explanations are clear
Regards,
François
The example uses
{ page: 'current' }
to sum the data on the page. Instead of that use{{ search:'applied' }
to sum the data based on the search results. If you still need help please provide a test case showing the problem.https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
hi Kevin ,
I have problms with tht JS code, could you help:
http://live.datatables.net/dehinumu/3/edit
Regards,
François
You have two things going on:
Please find updated test case here,
Colin
hi,
Ok, got it, thanks a lot
dont manage to do in this example, I want to set the code
"lengthChange": true,
"paging": true,
"searching": true,
"info": true,
"pageLength": 10,
"order": [[ 4, "desc" ]],
"language": {
"lengthMenu": "Affiche MENU par page",
"zeroRecords": "Rien à afficher",
"info": "Page PAGE sur PAGES, avec TOTAL résultats au total",
"infoEmpty": "Rien à afficher",
"infoFiltered": "(filtrage sur MAX données au total)",
"search": "Filtrer:",
"paginate": {
"first": "Premier",
"last": "Dernier",
"next": "Suivant",
"previous": "Précédent"
},
}
in the nex declaation of the tabl, but don't get the syntax
http://live.datatables.net/dehinumu/5/edit
As Colin explained you are getting this error because you are trying to initialize the Datatable twice:
Please read the technote in the link to learn how to troubleshoot and fix the error. Basically you need to combine all the config options into one initialization, like this:
http://live.datatables.net/jifowusa/1/edit
Also, as Colin said, you have an error with the salary for Garrett Winters. You have this:
Remove the trailing
0so you have
3.15 €`.Kevin
ok, but I want to add the following code in the JS part, and don't get thet syntax, can you halp ?
"lengthChange": true,
"paging": true,
"searching": true,
"info": true,
"pageLength": 10,
"order": [[ 4, "desc" ]],
"language": {
"lengthMenu": "Affiche MENU par page",
"zeroRecords": "Rien à afficher",
"info": "Page PAGE sur PAGES, avec TOTAL résultats au total",
"infoEmpty": "Rien à afficher",
"infoFiltered": "(filtrage sur MAX données au total)",
"search": "Filtrer:",
"paginate": {
"first": "Premier",
"last": "Dernier",
"next": "Suivant",
"previous": "Précédent"
Please update the test case to show the issue. Its hard to say what is wrong without seeing the problem.
Kevin
here is the test case updated ;
http://live.datatables.net/dehinumu/5/edit
In the JS, I want to include what is commented in the new table initialiastion above.
Did you see my example above which combines both?
http://live.datatables.net/jifowusa/1/edit
If you still need help please update the test case to show the issue. Meaning combine the code as your are trying so we can help debug.
Kevin
Hi, this works well but in fact my numbers are formatted whh ' ' to separate the thousand, then the sum does not work .
see : http://live.datatables.net/jifowusa/3/edit
I'm not comfortable at all in JS, how should I change the code so as it works and display the result formatted as well .
Thanks a million,
François
You've got
for Tiger Nixon, another bad value, so you need to fix that,
Colin
I know I have 1 12.50 € and this is what I want to be displayed, I want a ' ' to separate the thousandss, so how could we delete the ' ' in order ton make the total ?
That's fine, but then it's not a valid number so you can't do sums on it! You need to give the data as a number to do those calculations.
Colin
then how could I create a hidden column tha will containt tht numbers not formatted ?
if I add a ccolum, it will be pislayed and I want it hidden .
or in the function that calculates, I already remove the €, so can I remove the ' ' by the way ?
if yes, how ?
Look for this in your code:
The replace statement is used to remove non-numeric characters. Add a space and whatever other characters you need to remove to create a numeric value.
Kevin
great