refresh aggregate upon filtering

Hi 

I have treegrid control, which has filter functionality. while filtering grid. it does not update aggregates. Please see sample here 

https://stackblitz.com/edit/angular-enpmub-zkn6mq?file=app.component.ts


if you filter "Chang" on second column aggregate should be 50 instead it stays 200. is 


1 Reply

PS Pon Selva Jeganathan Syncfusion Team March 23, 2022 01:16 PM UTC

Hi Parth Rawal,   
  
Thanks for contacting syncfusion forum. 
 

Query: refresh aggregate upon filtering

 
Based on your query and shared sample, we understand you are handling the parent rows' aggregate column value based on the child column’s value. While filtering, the parent row value is not updated. We achieved your query by using the getCurrentViewRecords method of the treegrid. 
 
Please refer to the below code snippet, 
 
 totalChildValue(fielddatacolumn) { 
    var flag = false; 
    if (data.hasFilteredChildRecords) { 
      flag = true; // set the flag value while filtering 
    } 
    var treegrid = 
      document.getElementsByClassName('e-treegrid')[0].ej2_instances[0]; // treegrid instance 
    var childs = []; 
    if (isNullOrUndefined(data.parentItem) && flag == false) { 
      let totalUnitWeight = 0; 
      data.children.map((row=> (totalUnitWeight += row['UnitWeight'])); 
      return totalUnitWeight; 
    } else if (data.hasFilteredChildRecords && flag == true) { 
      // for filtered 
      var datanew = treegrid.getCurrentViewRecords(); // collect the current view records 
      for (var i = 0i < datanew.lengthi++) { 
        if (!isNullOrUndefined(datanew[i].parentItem)) { 
          childs.push(datanew[i]); // collect the child values 
        } 
      } 
 
      let totalUnitWeight = 0; 
      childs.map((row=> (totalUnitWeight += row['UnitWeight'])); // added the child values 
      return totalUnitWeight; 
    } 
    return data.UnitWeight; 
  } 
 
 
In the above code example, we enable the flag value based on the hasFilteredChildRecords property. Based on the flag and hasFilteredChildRecords property, collect the current view records using the getCurrentViewRecords method of the treegrid. Collect the child value based on the current view data. Then aggregate the value and update the value. 
 
Please refer to the below sample, 

Please refer to the below screenshot,

Kindly get back to us for further assistance. 
 
Regards,   
Pon selva   


Loader.
Up arrow icon