Our blazing fast Grid component built with pure JavaScript


Post by dmnewnham »

Once again - your support is excellent and looking for some guidance for my novice JS skills...

My question; how do I add the sum of one column to the groupRenderer:

For example, in this case (copied from the min/max Age example) I can find the max/min of "Completed" but how would I include the Total or Sum of completed?

{
field : 'category',
text : 'Category',
width : 250,
hidden: false,
groupRenderer({ groupRowFor, groupRecords,count }) {
const
max = groupRecords.reduce((max, r) => Math.max(r.Completed 0, max), 0),
min = groupRecords.reduce((min, r) => Math.min(r.Completed
0, min), max);

              

            return `${groupRowFor} - Number of records:  ${count} with max of ${max} `;
        }

},
where I'd like to return ${groupRowFor} - Number of records: ${count} with a total of ${sum};


Post by alex.l »

Hi dmnewnham,

You have the groupRecords array with all records in the group. You can count any sums you want.
Please, clarify the problem if I misunderstood you.

All best,
Alex

All the best,
Alex


Post by dmnewnham »

Apologies - I am very new to JavaScript and don't understand the nomenclature to get the sum of r.Completed into a variable.


Post by alex.l »

Please, read about loops in JS guides :)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration

Good luck,
Alex

All the best,
Alex


Post by dmnewnham »

Cool. Thanks. I wasn't sure if there was a smarter way to get a sum besides iterating. Implemented and working.


Post by Jokovich »

I have been looking for this information for a long time, I was very surprised when I found it here.


Post Reply