Subtotal aggregated column identififcation

Posted by: sravya_tamma on 21 April 2020, 5:38 am EST

    • Post Options:
    • Link

    Posted 21 April 2020, 5:38 am EST - Updated 3 October 2022, 7:00 am EST

    Hello,

    From the screenshot below:

    I have a “%Spend” column which is an aggregated column. I would like to have the numbers displayed next to subtotals to point to “NA” instead of 200%.

    Following is the code which is turning all the cells to NA. I’m trying to figure out how can I differentiate the subtotal column vs normal column (i.e., A1 )

  • Posted 21 April 2020, 4:50 pm EST

    Hi,

    In the formatItem event, you can check whether the current row is a GroupRow by using the instanceof operator:

    https://stackblitz.com/edit/angular-pzuyz5

    Regards,

    Ashwin

  • Posted 22 April 2020, 4:21 am EST

    Thanks Ashwin!

    One more question: I would like to export this grid to csv with all the formatted values present on UI. May I know from the below code how to call the formatItem during export to CSV ?

    if (docType === ‘csv’) {

    let grid = this.pivotGrid,

    rng = new CellRange(0, 0, grid.rows.length - 1, grid.columns.length - 1),

    csv = grid.getClipString(rng, true, true, true);

    this.exportFile(csv, ‘PivotGrid.csv’);

    }

    Thanks,

    Sravya.

  • Posted 22 April 2020, 7:49 pm EST

    Hi Sravya,

    The getClipString method is a simple method that returns the data bound to the cells of the FlexGrid. It does not know about the change in data done using innerHTML.

    But, I have asked the developers whether it can be achieved. The internal tracking id of the case is 432123. I will update you once I will hear from them.

    ~regards

  • Posted 24 April 2020, 6:14 am EST

    Thanks Ashwin!

  • Posted 27 April 2020, 7:26 pm EST

    Hi Sravya,

    The developer’s have provided a workaround on this. You may create your own getClipString method and use the CellFactory class to get the data for each of the cells. Using the CellFactory will provide the actual data displayed on the grid, whether it is the bound data or the data changed using innerHTML. Please refer to the sample below:

    https://stackblitz.com/edit/angular-qt3gzb

    ~regards

  • Posted 7 July 2020, 9:07 am EST - Updated 3 October 2022, 7:01 am EST

    Hi Ashwin,

    I tried to use the custom getClipString method and I’m able to get the formatted values. But i’m missing the rowFields and columnHeaders

    May i know how can i get the rowFields and columnHeaders ?

    Here is the code:

    . 
    
    export(docType: string) {
            if (docType === 'csv') {
                let grid = this.pivotGrid,
                rng = new CellRange(0, 0, grid.rows.length - 1, grid.columns.length - 1);
                let csv = this.getClipString(grid, rng);
                
                this.exportFile(csv, 'PivotGrid.csv');
                
            }
    }
    
    
    
    getClipString(grid, sel) {
            var text = "";
            let etemp = document.createElement("div");
            etemp.style.visibility = "hidden";
            grid.cells.hostElement.appendChild(etemp);
    
            // loop through selected rows/columns
            for (var r = sel.topRow; r <= sel.bottomRow; r++) {
                // var firstCell = true;
                for (var c = sel.leftCol; c <= sel.rightCol; c++) {
                    // if (firstCell) {
                    //     firstCell = false;
                    // } else {
                        text = text + ","; // comma after each cell
                    // }
    
                    // add cell text
                    grid.cellFactory.updateCell(grid.cells, r, c, etemp);
                    text += etemp.textContent.replace(/,/g,"");
                }
                text += "\n"; // new line after each row
            }
    
            // dispose of temporary cell
            grid.cellFactory.disposeCell(etemp);
            etemp.parentElement.removeChild(etemp);
            return text;
        }
    

    Below are the screenshots:

  • Posted 7 July 2020, 5:45 pm EST

    Hi Sravya,

    I have updated the getClipString method to include column and row headers. Please refer to the sample link below:

    https://stackblitz.com/edit/angular-qt3gzb

    ~regards

  • Posted 8 July 2020, 6:56 am EST

    Thank you!

Need extra support?

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

Learn More

Forum Channels