Display string value to pivot table values

2 Aug 20232 minutes to read

End user can display string value to the pivot table’s value cell by using the AggregateCellInfo event.

In the following example, each cell value of the Sold field’s actual value has been assigned from its combination data sets obtained from the args.cellSets in the AggregateCellInfo event.

@using Syncfusion.EJ2.PivotView

@Html.EJS().PivotView("pivotview").Height("300").DataSourceSettings(dataSourceSettings => dataSourceSettings.DataSource((IEnumerable<object>)ViewBag.DataSource).ExpandAll(false)
.FormatSettings(formatsettings =>
{
    formatsettings.Name("Amount").Format("C0").Add();
}).Rows(rows =>
{
    rows.Name("Country").Add(); rows.Name("Products").Add();
}).Columns(columns =>
{
    columns.Name("Year").Caption("Year").Add(); columns.Name("Quarter").Add();
}).Values(values =>
{
    values.Name("Sold").Caption("Units Sold").Add(); values.Name("Amount").Caption("Sold Amount").Add();
})).GridSettings(new PivotViewGridSettings { ColumnWidth = 140 }).AggregateCellInfo("aggregateCell").Render()
<script>
    function aggregateCell(args){
        if (args.fieldName === 'Sold') {
            args.value = secondsToHms(args.value);
        }
    }
    function secondsToHms(d) {
     d = Number(d);
     var h = Math.floor(d / 3600);
     var m = Math.floor((d % 3600) / 60);
     var s = Math.floor((d % 3600) % 60);
     return (
          ('0' + h).slice(-2) + ':' + ('0' + m).slice(-2) + ':' + ('0' + s).slice(-2)
     );
}
</script>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

Display string value to pivot table values