Auto resize columns to fit data width

6 posts, 1 answers
  1. Rohit
    Rohit avatar
    20 posts
    Member since:
    Dec 2017

    Posted 31 Jan 2018 Link to this post

    Hi

    How can the pivot grid auto resize the width of it's columns according to the width of it's column's data.

    PivotGridElement.BestFitHelper.BestFitColumns() doesn't work for me.

    Basically I want to execute the best fit function (provided in context menu for any column) for all members of ColumnGroupDescriptions and RowGroupDescriptions.

    Additionally, I want to hide the PivotRowDescriptorContainer, PivotFilterDescriptorContainer and PivotColumnDescriptorContainer when the pivotgrid has no data,

    or remove the "Drag data items here", "Drag row items here" and "Drag column items here" message that is displayed in this case so that the user doesn't try to do so (I am not using the RadPivotFieldList).

  2. Answer
    Hristo
    Admin
    Hristo avatar
    1522 posts

    Posted 31 Jan 2018 Link to this post

    Hello Rohit,

    Thank you for writing.

    The BestFitColumns method is working with column group descriptions. If you want to also best fit the row headers you can use the BestFitRowHeaders method and pass the levels for each of row group elements: 
    foreach (RadElement element in this.radPivotGrid1.PivotGridElement.RowDescriptorsArea.Children)
    {
        PivotGroupDescriptorElement group = element as PivotGroupDescriptorElement;
        if (group == null)
        {
            continue;
        }
     
        this.radPivotGrid1.PivotGridElement.BestFitHelper.BestFitRowHeaders(group.Level);
    }
     
    this.radPivotGrid1.PivotGridElement.BestFitHelper.BestFitColumns();

    Regarding your other question, I can suggest using a custom localization provider returning an empty string for the messages which need to be empty:
    class MyEnglishPivotGridLoclizationProvider : PivotGridLocalizationProvider
    {
        public override string GetLocalizedString(string id)
        {
            switch (id)
            {
                case PivotStringId.DragDataItemsHere: return "";
                case PivotStringId.DragColumnItemsHere: return "";
                case PivotStringId.DragItemsHere: return "";
                case PivotStringId.DragFilterItemsHere: return "";
                case PivotStringId.DragRowItemsHere: return "";
            }
     
            return base.GetLocalizedString(id);
        }
    }

    This documentation article demonstrates how the localization provider can be instantiated and used in the pivot control: https://docs.telerik.com/devtools/winforms/pivotgrid/localization/localization.

    Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Rohit
    Rohit avatar
    20 posts
    Member since:
    Dec 2017

    Posted 31 Jan 2018 in reply to Hristo Link to this post

    Hi Hristo

    The code for BestFit operation works if executed on UpdateCompleted event, but does not work if executed immediately after setting the LocalDataSourceProvider.

     

    Thanks for your help.

  4. Hristo
    Admin
    Hristo avatar
    1522 posts

    Posted 31 Jan 2018 Link to this post

    Hello Rohit,

    Yes, indeed. You will need to call this the best-fit logic once the control has updated and the row and column descriptions have been applied.

    Let me know if you have other questions.

    Regards,
    Hristo
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. Rohit
    Rohit avatar
    20 posts
    Member since:
    Dec 2017

    Posted 02 Feb 2018 Link to this post

    Hi Hristo

    The code to best fit rows and columns works correctly if the pivotgrid is visible, but it sets incorrect width if the grid is not visible on the UI.

     

  6. Hristo
    Admin
    Hristo avatar
    1522 posts

    Posted 05 Feb 2018 Link to this post

    Hi Rohit,

    The best-fit helper as perquisite assumes that the layout has been passed. If your control is not visible you can trigger a layout update before calling the logic for best fitting the columns using the RadControl.LoadElementTree method: 
    this.radPivotGrid1.LoadElementTree();
    //...
    this.radPivotGrid1.PivotGridElement.BestFitHelper.BestFitColumns();
     
    this.radPivotGrid1.Visible = true;

    Let me know if you have other questions.

    Regards,
    Hristo
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top