Aggregate values in the footer for selected rows

Hi,

is it possible displayed aggregate values in the footer only for selected rows?

Regards

3 Replies 1 reply marked as answer

VS Vignesh Sivagnanam Syncfusion Team May 19, 2021 12:15 PM UTC

Hi Kamil 
  
Greetings from Syncfusion support 
  
Based on your requirement we suspect that you want to calculate the value of the columns only from the selected records in the grid. To achieve your requirement, we suggest you use the custom aggregate feature in the Grid. 
  
Please refer the below code example and Sample for your reference, 
  
If you want to calculate the aggregate on initial selected records, you can use the below code. 
  
app.component.html 
  
<e-aggregates> 
      <e-aggregate> 
        <e-columns> 
          <e-column field="Freight" type="Custom" [format]="C2" [customAggregate]="customAggregateFn"> 
            <ng-template #footerTemplate let-data>Count: {{data.Custom}}</ng-template> 
          </e-column> 
        </e-columns> 
      </e-aggregate> 
    </e-aggregates> 
  
……………………………………………………………………… 
app.component.ts 
  
customAggregateFn(data, column) { 
    var grid = (document.getElementById('Grid') as any).ej2_instances[0]; //Grid Instance 
    var r = 0; 
    for (var i = 0; i < grid.getSelectedRecords().length; i++) { 
      r = grid.getSelectedRecords()[i].Freight + r; 
    } 
    return r; 
  } 
  
If you want to calculate the aggregate the by selecting and deselecting the rows after grid rendering, you need to use the below code and refresh the grid aggregate module while selecting and deselecting the records using EJ2 Grid rowSelected and rowDeselected event. 
  
rowSelected(args) { 
    (this.grid.aggregateModule as any).refresh(); 
  } 
  
  deselect(args) { 
    (this.grid.aggregateModule as any).refresh(); 
  } 
  
 
  
Regards 
Vignesh Sivagnanam 


Marked as answer

KK Kamil Krzyzanski June 7, 2021 10:52 AM UTC

It works perfectly. This is what I meant. Thank you for help.

Regards


VS Vignesh Sivagnanam Syncfusion Team June 8, 2021 08:41 AM UTC

Hi Kamil 
  
Thanks for the update 
  
We are happy to hear that the provided solution works fine at your end. 
  
Please get back to us if you need any further assistance. 
  
Regards, 
Vignesh Sivagnanam 


Loader.
Up arrow icon