rowGroup does not sum values
rowGroup does not sum values
Good afternoon !
I have the following problem when trying to summarize the values of grouped rows.
I leave two examples available, of identical code, except for one line
Example 1: https://pavanconsultores.com.ar/pruebas/pru04a.php
Code:
var salaryAvg = rows
.data()
.pluck('fld.fld_sem_09')
.reduce( function (a, b) {
// return a + b.replace(/[^\d]/g, '')*1;
return a;
}, 0);
Example 2: https://pavanconsultores.com.ar/pruebas/pru04b.php
Code:
var salaryAvg = rows
.data()
.pluck('fld.fld_sem_09')
.reduce( function (a, b) {
return a + b.replace(/[^\d]/g, '')*1;
// return a;
}, 0);
Note that the only difference is the comment on line 6 and 7 on both sides.
In example 1 the groups are shown correctly, but they do not sum the totals.
In example 2 the groups and totals are not shown.
Any ideas or help for group totals to be displayed correctly ?
Thank you
Answers
The second one is giving an error
So
b
isundefined
, causingb.replace
to fail. I suspect thatundefined
is in your dataset - just do a check for it before doing thereplace
.Colin
Hi Colin, I had noticed, but I don't understand how I should solve it.
If I look at the documentation I used as a guide, I don't find that reference:
https://datatables.net/extensions/rowgroup/examples/initialisation/customRow.html
Could you give me some other detail?
Thank you !
I just took another look and I think you've found a bug - it seems
pluck()
doesn't like it when there's a nested object - there's a simple example of that here. I've raised it internally (DD-1386 for my reference) and we'll report back here when there's an update.In the meantime, you can do this without
pluck()
, and justreduce()
. Something like this:Colin