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

[Solved] ResizeToFit - do not take column header into consideration

2 Answers 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Baal
Top achievements
Rank 1
Baal asked on 11 Mar 2013, 08:19 PM
I have RadGrids in my application that need the columns resized by their content; however, I do not want to include header into consideration for resize.

For example, in the grid below, the content of Contact Person Name is almost always empty. Using the code below, the Contact Person Name becomes as wide as it needs to be to fit the header in one single row. But I do not care about the header content, it can be split into multiple lines if need be. If all the 25 rows in a page is empty for this record, I'd rather the header be split into three lines (one per word) and have a small column.

<telerik:RadGrid ID="rgCompany" runat="server" AutoGenerateColumns="false" EnableViewState="true"
    PageSize="25" AllowSorting="true" AllowMultiRowSelection="true" AllowCustomPaging="true"
    OnNeedDataSource="rgCompany_NeedDataSource" OnSortCommand="rgCompany_SortCommand"
    OnItemDataBound="rgCompany_ItemDataBound">
     
    <PagerStyle Mode="NextPrevNumericAndAdvanced" Position="Bottom" AlwaysVisible="True" />
 
    <ClientSettings EnableRowHoverStyle="true">
        <Selecting AllowRowSelect="true"></Selecting>
        <Resizing AllowColumnResize="True" ResizeGridOnColumnResize="True" AllowResizeToFit="True"></Resizing>
        <ClientEvents OnRowSelected="RowSelected" OnRowDeselected="RowDeselected" />
    </ClientSettings>
     
    <MasterTableView>
        <telerik:GridBoundColumn UniqueName="Name" HeaderText="Company Name" DataField="CompanyName" />
        <telerik:GridBoundColumn UniqueName="City" HeaderText="City" DataField="City" />
        <telerik:GridBoundColumn UniqueName="State" HeaderText="State" DataField="State" />
        <telerik:GridBoundColumn UniqueName="Zip" HeaderText="Zip" DataField="Zip" />
        <telerik:GridBoundColumn UniqueName="Phone" HeaderText="Phone Number" DataField="PhoneNumber" />
        <telerik:GridBoundColumn UniqueName="Contact" HeaderText="Contact Person Name" DataField="ContactName" />
    </MasterTableView>
 
</telerik:RadGrid>


I'm calling this function from the javascript pageLoad of all pages that contain grid.

function resizeGridToFitColumnContent (grid) {
    var masterTable = grid.get_masterTableView();
    var columns = masterTable.get_columns();
     
    for (var i = 0; i < columns.length; i++) {
        columns[i].resizeToFit();
    }
}


Can this be achieved?

Also, sometimes if the grid is long (a lot of columns) it takes more than a few seconds for the page is load up. The screen goes white until the calculation is done and grid is displayed. How can I easily provide a message during this time?

2 Answers, 1 is accepted

Sort by
0
Antonio
Top achievements
Rank 1
answered on 12 Mar 2013, 10:27 AM
excuse me, yi have the same problem, you have resolved?
0
Galin
Telerik team
answered on 14 Mar 2013, 02:12 PM
Hello Baal,

The resizeToFit feature is a resource-heavy operation, it involves a lot of DOM and circles all cells in the column. This may be a little slower.

However, you can use the Ajax Loading Panel during the time of operations. For more information please refer to this demo page.

I hope this helps.

Regards,
Galin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Baal
Top achievements
Rank 1
Answers by
Antonio
Top achievements
Rank 1
Galin
Telerik team
Share this question
or