Total per page and Grand Total

Hi all, for my grid i would like to show, for every page, the grand total and the page total.

How can i acheive this


Thanks

Stefano


1 Reply

PS Pavithra Subramaniyam Syncfusion Team November 15, 2021 09:28 AM UTC

Hi Stefano, 

Thanks for contacting Syncfusion support. 

You can achieve your requirement by using the custom aggregate function. Please refer to the below sample in which we have shown Grand total by using the default sum aggregate and per page total by using custom aggregate function. 

<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" allowPaging="true"> 
    <e-grid-aggregates> 
       <e-grid-aggregate> 
            <e-aggregate-columns> 
                <e-aggregate-column  field="Freight" type="Sum" footerTemplate="Grand Total:${Sum}"></e-aggregate-column>                         
            </e-aggregate-columns> 
        </e-grid-aggregate> 
        <e-grid-aggregate> 
            <e-aggregate-columns> 
                <e-aggregate-column field="Freight" type="Custom" footerTemplate="Page Total:${Custom}" customAggregate="@("customAggregateFn")"></e-aggregate-column> 
            </e-aggregate-columns> 
        </e-grid-aggregate> 
    </e-grid-aggregates> 
    <e-grid-pagesettings pageCount="5"></e-grid-pagesettings> 
    <e-grid-columns> 
        <e-grid-column field="Freight" headerText="Freight" textAlign="Right" format="C2" width="160"></e-grid-column> 
        .  .  . 
    </e-grid-columns> 
</ejs-grid> 
 
<script> 
    function customAggregateFn(data, aggColumn) { 
        var grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0] 
        // Queried the result with Grid page size and required aggregate using EJ2 DataManager 
        return new ej.data.DataManager(data.result).executeLocal( 
    new ej.data.Query().skip 
      .take(grid.pageSettings.pageSize) 
      .requiresCount() 
      .aggregate('sum', aggColumn.columnName) 
  ).aggregates[aggColumn.columnName +' - sum']; 
    } 
</script> 



Please get back to us if you have any queries. 

Regards, 
Pavithra S 


Loader.
Up arrow icon