Custom aggreage function in Group ng-template & change detection

Posted by: develop on 30 June 2020, 6:20 pm EST

  • Posted 30 June 2020, 6:20 pm EST

    Hi guys,

    I’m facing a huge performance issue with that kind of code :

                <wj-flex-grid-column header="Total" [binding]="'Total'" [aggregate]="'Sum'">
                    <ng-template wjFlexGridCellTemplate [cellType]="'Group'" let-cell="cell">
                        <span i18>srv:</span> <b>{{ myCustomCalculation(cell) }}</b>
                    </ng-template>
                </wj-flex-grid-column>
    

    The combination of :

    • Angular change detection, which triggers the myCustomCalculation function a HUGE lot of time,
    • myCustomCalculation function is dealing with/aggregating all the records of the cell.item.items,
    • the groups descriptions that are at the user’s discretion often results with nested GroupRows (I saw up to 6 levels) and then many, many GroupRows…

      obviously makes the whole thing unmanageable.

    So, considering the function call in the view data-binding beeing a bad pattern, how would you advice to solve the issue ?

    I tried to calculte the aggregated results in some variables, but having nested (and user-managed) groups makes it tricky.

    Maybe you have some code example or idea to help.

    Thanks a lot !

  • Posted 1 July 2020, 5:20 pm EST

    Hi,

    Could you please share the following information?

    • "

    • “What type of calculation you are trying to get aggregate?”

    • "At what level you are trying to apply to the group? "

    • “Handling the ChangeDetection explicitly?”

    • “Is it possible to share code snippet for grouping and custom calculation?”

    • " Simple demo sample depicting your issue"

    "

    Regards,

    Manish Gupta

  • Posted 1 July 2020, 6:13 pm EST

    Hi,

    About the context, the gris is used for picking reports.

    1. I’m calculating a ratio per hour, but based on many days. So I crawl the data, sum the parcel amount / time per day based on the first&last record per day, and make an average out of them. Theunusual thing is I have to filter out non-working times.

    2. Not sure I understand the question, but those are subtotals groups, based on the drag’n’drop GroupPanelhttps://www.grapecity.com/wijmo/api/classes/wijmo_grid_grouppanel.grouppanel.html. The customer is using the grid for many purposes (stats per picker, per order, per business day, …) so the groups are always changing.

    3. I’m not handling it explicitly at this time, but it could be a solution. Quite tricky I think; because I’d have to make make sure that I won’t miss events (group handling, data changes, data outside of the view that appears on scroll) and to be honnest, I’m a bit affraid about it.

    4. Gouping is standard from GroupPanel.

      The custom calc is below.

    (I saw some code sample running getAggregate() and getColumn(‘’).aggregate and maybe it’s a way to go ?)

    calculatePerHour(a): number {
    	let items: Typings.PickingReportDto[] = a.item.items;
    
    	let min: Date = null;
    	let max: Date = null;
    	let day: number;
    	let tot = 0;
    	let parcels = 0;
    	items.forEach(item => {
    		parcels += item.pp;
    		if (day && item.dd !== day) {
    			tot += max.getTime() - min.getTime();
    			min = null;
    			max = null;
    		}
    		day = item.dd;
    
    		if (!min || item.dt < min) {
    			min = item.dt;
    		}
    		if (!max || item.dtE > max) {
    			max = item.dtE;
    		}
    	});
    	if (min && max) {
    		tot += max.getTime() - min.getTime();
    		min = null;
    		max = null;
    	}
    	return parcels / (tot / (1000 * 3600));
    }
    
    1. I’ll try to provide an example on an editor, but I’m not used to that and it’s always a fight :slight_smile:

    Thanks for your help !

  • Posted 2 July 2020, 11:52 pm EST

    Hi,

    Thank you for the information. We are working on this and will update you as soon as possible.

  • Posted 5 July 2020, 11:08 pm EST

    Hi,

    We tried to implement custom aggregation and we do not see the huge performance issue with the FlexGrid.

    Please refer to the attached sample for reference.

    Regards,

    Manish Gupta

    FlexGrid-GrpPanel-CustomAgg.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels