Cumulative sum in Flexgrid + Angular

Posted by: frederic.jammes on 14 June 2018, 3:00 am EST

    • Post Options:
    • Link

    Posted 14 June 2018, 3:00 am EST

    Hello,

    I’m using Wijmo 5.2x in an Angular 5 project and I would like to have a cumulative sum on a column in a FlexGrid.

    Here’s an example to illustrate what I mean :

    Each line has 3 columns (let’s call those A, B and C for the example). The value of C in the first line is B - A.

    In the following lines, I want to have C to be equal to (C of the previous line) + B - A.

    Is this possible easily ?

    Thank you for your help.

    Regards,

    Frédéric

  • Posted 14 June 2018, 10:40 pm EST

    Hi,

    You may do that by adding a column in the grid.columns array and updating its value as required using setCellData() method.

    Please refer to following code snippet:

    /* push a column on columns array */
    grid.columns.push(new wjcGrid.Column({
    	header:"custom val"
    }));
    /* update value */
    grid.rows.forEach((row,rIndex)=>{
    	var rData=row.dataItem;
    	var val=rData["B"]-rData["A"];
    	if(rIndex!=0){
    		val+=grid.getCellData(rIndex-1,grid.columns.length-1);
    	}
    	grid.setCellData(rIndex,grid.columns.length-1,val,true,true);
    });
    

    Here is an example of the same:- https://stackblitz.com/edit/angular-gwnj41?file=app%2Fapp.component.ts

    You may also use FlexSheet control to use some Excel formulas. Please refer to the following demo sample:

    http://demos.wijmo.com/5/Angular2/ExcelBook/ExcelBook/excellikeSheet.htm

    ~Manish

Need extra support?

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

Learn More

Forum Channels