OLAP: How to auto size WjPivotGrid columns

Posted by: james.ingham on 18 May 2020, 5:03 pm EST

  • Posted 18 May 2020, 5:03 pm EST - Updated 3 October 2022, 6:00 am EST

    Dear support,

    I am wondering whether there is a neat way to autosize all columns based on both * “header name”

    and * “column data”

    in WjPivotGrid. Apparently if I check/uncheck fields on pivot panel, the pivot grid wouldn’t do autoResizeColumns itself. It’s easy to demonstrate this. Just go to your official OLAP demo page (I can’t paste the link because it always triggers your spam detection.)

    and execute following code in console:

    
    pivotGrid = wijmo.Control.getControl($('wj-pivot-grid'))
    pivotGrid.autoSizeColumns()
    
    

    You will see column widths have changed. This is the trick we are currently using to resize columns in PivotGrid.

    However there’s still a problem here. After doing pivotGrid.autoSizeColumns(), if you click any of the column headers for sorting purpose, the column would go back to its original size… Is there a way to solve this issue?

    An interesting finding is that if you change columns width manually, e.g. drag-n-drop column borders, its width would then be persisted. It looks like changing column width manually would not only write the new width to pivotGrid.columns[index].width, but also to ngFmt.fields[index].width, however calling autoSizeColumns() function wouldn’t have any effect in ngFmt.fields. I guess there might be a missing event not being triggered by autoSizeColumns() API but by manually drag-n-drop columns borders.

    We hope you can help us to find a neat way of auto sizing pivot grid columns.

  • Posted 19 May 2020, 6:05 pm EST

    Hi James,

    If autoSizeColumns is working for you, then you can keep using that in your application. For auto sizing after every update, call this method in the updatingView event of the PivotGrid.

    Regarding the changing width, your observation is correct. The autoSizeColumns only set the width of the Column instead of Field. I have asked the developers on whether this is an expected behavior or not. The internal tracking id of the case is 436598. I will update you once I will hear from them.

    Regards,

    Ashwin

  • Posted 21 May 2020, 1:08 pm EST

    Hi Ashwin, thanks for your feedback. We are looking forward to the fix :slight_smile:

  • Posted 21 December 2020, 10:43 pm EST

    Hi James,

    The developers have said that this is by design. This is because, when auto-sizing the columns in the grid, the columns bound to the same fields can be auto-sized with different widths and we cannot assign different widths to the same field.

    That is why auto-sizing only works on the grid level.

    ~regards

Need extra support?

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

Learn More

Forum Channels