Aggregate multi parent

I have multiple hierarchy and I want to aggregate data for it once i edit cell in child. It is working fine for 1 level but it does not aggregate further. however, after i save data and then reload the grid. it shows as expected. Below is the code I have used in 

valueAccessor


once i finish edit on actioncomplete I refresh the grid as well. 

const totalChildPoint= function (field:any, data:any, column:any) {
try{
if (!isNullOrUndefined(data.hasChildRecords)) {
//checking if the record has children
let total = 0;
//findChildrenRecords(data).map(row => {total += row[parseInt(field)];});
data.childrens.map(row =>
(total += row[parseInt(field)])
);
return total;
}else{
return data[field];
}
}catch(e){
console.log("Error while calculating total");
console.log(e);
return 0;
}

3 Replies

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team January 11, 2022 03:40 PM UTC

Hi Parth Rawal, 

Query#:- I have multiple hierarchy and I want to aggregate data for it once i edit cell in child. It is working fine for 1 level but it does not aggregate further 

We have checked your reported problem and by using findChildRecords method imported from ej2-treegrid packages and we have calculated the total multiple levels and display it in parent records. 

Refer to the code below:- 
  import { findChildrenRecords } from '@syncfusion/ej2-treegrid'; 
 
    totalChildProgress(field, data, column) { 
        if (!isNullOrUndefined(data.hasChildRecords)) { 
          //checking if the record has children 
          let totalUnitWeight = 0; 
          //using findChildrenRecords method to get deep children records and calculate sum for it 
          findChildrenRecords(data).map(row => { 
            //summing child value to show them in parent 
            totalUnitWeight += row['Progress']; 
          }); 
          return totalUnitWeight; 
        } 
        return data.Progress; 
      } 


Kindly share more details in elaborate or replicate the issue in the above sample if we misinterpreted your query. 

Regards, 
Farveen sulthana T 



PD PDev January 12, 2022 10:20 AM UTC

I think you have not read my question fully. it shows aggregate on all level once i save data and then reload the page. 

Also, your example does not allow me to edit cell. Can you please create sample which will allow me to edit cell and based on user input. it should roll up values on all level


Parent 1____________________________________10                                          

        child 1.1_______________________________10

               Child 1.1.1_________________________5

               Child 1.1.2_________________________5


Hope i am clear now



FS Farveen Sulthana Thameeztheen Basha Syncfusion Team January 13, 2022 04:01 PM UTC

Hi Parth Rawal,  

We have checked your query and while on Editing we have to refresh TreeGrid to reflect the changes because we have performed the calculations through valueAccessor.  


Screenshot:
 
Screenshot while Editing:- 
 


We have shown the calculated value from Actual value of the Progress and displayed it in the another column. Also we need to refresh the changes to show the calculated value. 

If we misinterpreted your query or your requirement is different from above, please share issue replicable sample/ Screenshot for demonstration and type of Editmode you have used to proceed further. 

Regards, 
Farveen sulthana T 



Loader.
Up arrow icon