I was able to get it working using the "filter" event.
Do you see any issues with the below?
$grid.on('pqGrid:filter', function (e, ui) {
if (ui.rules.length > 0) {
var grid = gridAPI.grid;
var DM = grid.options.dataModel;
var includeRows = [];
DM.data.forEach(function (row) {
//Find the children for this row
var rowChildren = DM.dataUF.filter(function (x) {
return x.parentId == row.ROLE_ID;
});
//remove the children from the unfiltered data
DM.dataUF = DM.dataUF.filter(function (el) {
return !rowChildren.includes(el);
});
//Match the hide state of children to the parent close state
row.pq_close = true;
rowChildren.forEach(function (value) {
value.pq_hidden = row.pq_close;
});
//add the children back to the row
row.children = row.children.concat(rowChildren);
//add to list of children to include in data
includeRows = includeRows.concat(rowChildren.filter(function (el) { return !DM.data.includes(el); }));
});
//update data with the children we added
DM.data = DM.data.concat(includeRows);
//sort the data again
DM.data = grid.iSort.sortLocalData(DM.data);
}
});