Hi,
I'd like to select the last value instead of summing the values, when using the pivot table.
I've read the docs here https://ej2.syncfusion.com/react/documentation/pivotview/calculated-field#:~:text=Allows%20end%20user%20to%20create,invoked%20from%20Field%20List%20UI.
And no existing "last" function.
Is there a way to byo agg func?
Cheers,
Hi Joe,
We would like to let you know that the pivot table by default displays aggregated data in all value fields and summary values in the grand total columns. However, you can able to customize the pivot value cells based on your needs by using the aggregateCellInfo event. In this below code example, we have customized the grand total value cells by displayed its last raw data value using the aggregateCellInfo event. Please refer the below code example.
Code example:
|
function aggregateCellInfo(args){ // You can customize the column grand total here. if(args.fieldName == "Total" && args.columnCellType == "grandTotal"){ // Here, you get the raw data of the specific cells using args.cellSets and we have displayed the last raw data for the column grand total here. args.value = args.cellSets[args.cellSets.length - 1]['Sold']; } // You can customize the row grand total here. else if(args.fieldName == "Total" && args.rowCellType == "grandTotal"){ args.value = '10'; } } |
Output screenshot:
Meanwhile, we have prepared a sample for your reference.
Sample: https://stackblitz.com/edit/react-u1kuv6-tem8e8?file=index.js
Please refer the below UG document to know more about aggregateCellInfo event
Document: https://ej2.syncfusion.com/react/documentation/pivotview/aggregation/#aggregatecellinfo
Regards,
Angelin Faith Sheeba.
Thanks for your response.
So if I simply did this:
function aggregateCellInfo(args){
args.value = args.cellSets[args.cellSets.length - 1]['Sold'];
}
would that essentially set every cell value to the last value in cellSets ?
Hi Joe,
Yes, if you haven’t provided any condition to customize the values in the “aggregateCellInfo” event, it changes all the pivot value cells in the pivot table because aggregateCellInfo event triggers for every value cells in the pivot table.
Please refer the below UG document to know more about aggregateCellInfo event.
Document: https://ej2.syncfusion.com/react/documentation/pivotview/aggregation/#aggregatecellinfo
Regards,
Angelin Faith Sheeba.