This is a migrated thread and some comments may be shown as answers.

Auto resize columns to fit data width

5 Answers 137 Views
PivotGrid and PivotFieldList
This is a migrated thread and some comments may be shown as answers.
Rohit
Top achievements
Rank 1
Rohit asked on 31 Jan 2018, 08:48 AM

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).

5 Answers, 1 is accepted

Sort by
0
Accepted
Hristo
Telerik team
answered on 31 Jan 2018, 11:41 AM
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.
0
Rohit
Top achievements
Rank 1
answered on 31 Jan 2018, 01:08 PM

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.

0
Hristo
Telerik team
answered on 31 Jan 2018, 01:21 PM
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.
0
Rohit
Top achievements
Rank 1
answered on 02 Feb 2018, 01:17 PM

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.

 

0
Hristo
Telerik team
answered on 05 Feb 2018, 07:30 AM
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.
Tags
PivotGrid and PivotFieldList
Asked by
Rohit
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Rohit
Top achievements
Rank 1
Share this question
or