Knowledge Base Article

Grand Total (Sum) Row In Table With Aggregation

Apply the following script on a table with aggregation's widget script to create a row with Grand Totals.
This will be considered as just another value and may not always appear on the first page of results if results are paginated.
widget.on('processresult', function(a,b){
 var totals = b.result.$$rows.reduce((arr,cur) => arr.map((val, i) => ({ data: val.data + cur[i].data })));
 totals[0].data = 'Grand Total';
 totals.forEach(function(i){
  i.text = i.data.toString()
 });
 b.result.$$rows.push(totals);
})
Updated 03-02-2023

1 Comment

  • TJT's avatar
    TJT
    Data Storage

    Is it possible to show Grand Total only for specific columns, basically only the aggregated columns.

    Thanks

    TJ