Filtering and Sorting statemachine issue

Hi, I wrote a subtotal for Grid groups. I try to keep the row at the bottom of each group. My issue is that whenever a user filters it needs to be recomputed and when its sorted it gets moved. So I made 2 functions 1 that removes the subtotals, by id, and another that adds subtotals, which does the computation.

I then,

            <code>grid.attachEvent(
                "onAfterSorting",
                function(index,type,direction){
                    removeSubtotalsToGroups();
                    addSubtotalsToGroups();
                }
            );
            grid.attachEvent(
                "onFilterEnd",
                function(elements){
                    removeSubtotalsToGroups();
                    addSubtotalsToGroups();
                }
            );</code>

I put alerts in those callbacks and they get called when I do sortings or filters but the rows are put into the wrong locations.

If I do this (some repeated) in a callback for onXLE:
grid.attachEvent(
“onBeforeSorting”,
function (ind,type,direction){
removeSubtotalsToGroups();
addSubtotalsToGroups();
return true;
}
);
grid.attachEvent(
“onAfterSorting”,
function(index,type,direction){
removeSubtotalsToGroups();
addSubtotalsToGroups();
}
);
grid.attachEvent(
“onFilterStart”,
function(indexes,values) {
removeSubtotalsToGroups();
addSubtotalsToGroups();
return true;
}
);
grid.attachEvent(
“onFilterEnd”,
function(elements){
removeSubtotalsToGroups();
addSubtotalsToGroups();
}
);

It works only if I add these 4 extra remove/adds. I put alerts into all of them and see them being called many times. I don’t know if their events are messed up or if maybe groupby calls sorting or filter and the docs don’t say. Does anyone know why it seems like onFilterEnd and onAfterSorting don’t seem like they are really at the end of filtering and the end of sorting?

Oh the reason I’m asking about this is because this is making the js really slow. If it only ran once for each action the user did it would be fine. I almost need a dirty flag that gets set whenever the user hits the sort or filter or refresh functions, maybe.

My main question I guess is how can I just remove and add subtotals when the user does something to the groups?

Grouping changes the way how sorting and filtering is applied

In case of sorting - if you have used attachEvent before groupBy call - sorting events must be processed in correct order

  • onBeforeSorting
    sorting rows
  • onAfterSorting

as for filtering , in case of group by the order of operation will look as

  • onFilterStart
    filtering
  • onFilterEnd
    applying grouping to filtered set

so onFilterEnd will occur before final grouped view is available
Instead of onFilterEnd you can use onGroup - it is called each time when groupBy applied ( and in case of filtering - when rows regrouped after filtering )

Is there an event for after groupby. I’m asking because I want to insert a row after grouping. If grid is supposed to stop that from happening is there a way to fix a row to the bottom of the groups?