Problem with Columns width

6 posts, 0 answers
  1. Daniel
    Daniel avatar
    159 posts
    Member since:
    Feb 2014

    Posted 21 Jul 2014 Link to this post

    Hello,

    I am working on a project with a RadGrid that has DetailView.
    The RadGrid has a lot of columns.
    I want the columns’ width to auto-size by content.

    I have the following code: 
    VB.NET:
    RadGrid1.AllowSorting = True
    adGrid1.MasterTableView.AllowSorting = True
    adGrid1.ClientSettings.Scrolling.UseStaticHeaders = True
    adGrid1.MasterTableView.PageSize = 30
    adGrid1.MasterTableView.AllowPaging = True
    adGrid1.AllowPaging = False

    ASPX:
        <style type="text/css">
     
            #RadGrid1Panel, .RadGrid, .RadGrid_Default{
                width: 700px !important;
            }
        </style>
     
    <telerik:RadGrid ID="RadGrid1" runat="server" MasterTableView-EnableHeaderContextMenu="true" Height="900px" Width="700px" >
                                <ClientSettings>
                                       <Scrolling AllowScroll="True"></Scrolling>
                                     
                                </ClientSettings>
     </telerik:RadGrid>

    When I add the following code, all columns’s width get “squashed”:
    Dim tableViewOrders = New GridTableView(RadGrid1)
    RadGrid1.MasterTableView.DetailTables.Add(tableViewOrders)

    How can I solve this?

    I have attached video link that shows this issue:
    [video link]


    Thanks,
    Daniel.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 21 Jul 2014 in reply to Daniel Link to this post

    Hi Daniel,

    Please set HeaderStyle-Width property for grid columns which is required when static headers are enabled. Also, note that it is not recommended to set ItemStyle-Width.

    ASPX:
    <telerik:RadGrid ID="RadGrid1" runat="server" MasterTableView-EnableHeaderContextMenu="true" Height="900px" Width="700px"  >
      <HeaderStyle Width="100px" />
        <ClientSettings>
          <Scrolling AllowScroll="True"></Scrolling>
        </ClientSettings>
    </telerik:RadGrid>

    Thanks,
    Princy
  3. Daniel
    Daniel avatar
    159 posts
    Member since:
    Feb 2014

    Posted 23 Jul 2014 in reply to Princy Link to this post

    Hi Princy,

    Thank you for the solution.

    However, this solution is not good for my project because each column gets a fixed size.
    My project needs that each column’s size will be according to that column’s content.

    I will be glad if you can provide such a solution!

    Thanks,
    Daniel.
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Jul 2014 in reply to Daniel Link to this post

    Hi Daniel,

    Another way to adjust column width is to fit the widest cell's content without wrapping, you can take a look at this documentation on resizeToFit.

    Thanks,
    Princy
  5. Daniel
    Daniel avatar
    159 posts
    Member since:
    Feb 2014

    Posted 23 Jul 2014 in reply to Princy Link to this post

    Hi Princy,

    Thank you for the quick solution.

    However, this solution is not good for my project because it works only on the MasterTableView and not on the DetailView.

    I will be glad if you can provide a solution that works also on the DetailView!

     
    Thanks,
    Daniel.
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 24 Jul 2014 in reply to Daniel Link to this post

    Hi Daniel,

    The only way to have the alignment correct is remove the UseStaticHeaders property, or if you want to set this property, you will have to set the HeaderStyle.Width, which is mentioned here.

    Thanks,
    Princy
Back to Top