Setting Subtotal removes the grand total - In Olap PivotGrid

Posted by: sravya_tamma on 26 May 2020, 9:31 am EST

  • Posted 26 May 2020, 9:31 am EST

    Hello,

    On PivotGrid initialization, I was able to create GrandTotal and move it to the top:

    this.ng = new wjOlap.PivotEngine({
                        itemsSource: this.data,
                        fields: this.constructValueAddFields(),
                        rowFields: ['ColumnHeader1', 'ColumnHeader2'],
                        valueFields: [],
                        showRowTotals: 'Subtotals',
                        totalsBeforeData: true
                    });
    

    Issue is: I have a subtotal button. When its clicked I need to display subtotals.

    Subtotals are displayed correctly, but this action wipes out GrandTotal.

    Below is the code:

    subTotalAndGrandTotal() {
            this.pivotGrid.engine.showRowTotals = wjOlap.ShowTotals.None;
            this.pivotGrid.engine.showRowTotals = this.level === 1 || this.level === 2 || this.level === 3  || this.level === 4  ? wjOlap.ShowTotals.Subtotals : wjOlap.ShowTotals.None;
            this.pivotGrid.engine.totalsBeforeData =  true;
            this.pivotGrid.refresh();
        }
    

    May I know how can I prevent it from removing the GrandTotal?

  • Posted 26 May 2020, 5:45 pm EST

    Hi Sravya,

    If you will set the showRowTotals to GrandTotals instead of None, then only grand totals will be displayed. And then if you wish to show subtotals, then set its value to Subtotals.

    Also, can you please explain what does this.level variable do? It seems that you are setting the showRowTotals value according to this.level.

    Regards,

    Ashwin

  • Posted 26 May 2020, 6:07 pm EST

    Hi Ashwin,

    But, how can I set to have both subtotal and grand total to be displayed on the grid?

    From your reply I understand that setting subtotal removes the grand total and vice versa.

    Level is the input provided by a user which indicates on which row field they would like to see the sub totals for.

    Thanks

    Sravya

  • Posted 27 May 2020, 4:34 am EST

    HI Ashwin,

    I think I figured the issue.

    During Grid creation, I was using loadedRows event which actually looks at level (input from user) and it hides the subtotal from those row/column. which is what is removing the GrandTotal from the top row. So, I fixed it by skipping the toprow and it worked.

    loadRows(s, e) {
            let index = 0;
            s.rows.forEach(r => {
                if(index != 0) {
                    for (let i = 0; i < 5 ; i++) {
                        if(i != this.level && r.dataItem.$rowKey.level == i ){
                            r.visible = false;
                        }
                    }
                }
                index++;
            });
        }
    
  • Posted 27 May 2020, 2:44 pm EST

    Hi Sravya,

    It seems that your issue if fixed.

    Let us know in case you face any other issues.

    ~regards

Need extra support?

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

Learn More

Forum Channels