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(field, data, column) {
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 = 0; i < datanew.length; i++) {
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