align column content and auto fit column

10 posts, 2 answers
  1. appdev
    appdev avatar
    223 posts
    Member since:
    Sep 2008

    Posted 02 Jun 2011 Link to this post

    this is how i generate my data into the grid
    <telerik:RadGrid ID="grid_Historical_Commodity" runat="server" Visible="false" Width="995px" Height="450px"  />
     grid.Visible = True
            grid.ClientSettings.Scrolling.UseStaticHeaders = True
            grid.ClientSettings.Scrolling.AllowScroll = True
            grid.ClientSettings.Resizing.AllowColumnResize = True

            Dim rs As SqlDataReader = Nothing
            rs = getdata()

                Dim dt As Data.DataTable = New Data.DataTable
                dt.Load(rs)
                grid.DataSource = dt


    how do i make it so that the content in certain columns are center and each column has a fixed size. thanks
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 03 Jun 2011 Link to this post

    Hello Duy,

    Try setting CSS class for the columns  from the ItemDataBound. Here is a sample code.
    C#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridDataItem)
           {
               GridDataItem item = (GridDataItem)e.Item;
               item["ColUniqueName"].CssClass = "textCenter";
           }
       }
    CSS:
    .textCenter
           {
            text-align:center !important;
           }

    For your second requirement set the TableLayout="Fixed"
    aspx:
    <telerik:RadGrid ID="RadGrid3" DataSourceID="SqlDataSource3" AutoGenerateColumns="true"  AllowPaging="True" runat="server" >
       <HeaderStyle Width="100"/>     
           <MasterTableView TableLayout="Fixed"  >
              ....

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. appdev
    appdev avatar
    223 posts
    Member since:
    Sep 2008

    Posted 03 Jun 2011 Link to this post

    the text align works great thank you for that.

    what if i want to assign certain column to certain width, how would i do that on the server side? thanks.
  5. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 Jun 2011 Link to this post

    Hello Duy,

    You can set the column width in the PreRender as follows.
    C#:
    protected void RadGrid1_PreRender(object sender, EventArgs e)
       {
           RadGrid1.MasterTableView.GetColumn("ColUniqueName").HeaderStyle.Width = Unit.Pixel(300);
       }

    Thanks,
    Shinu.
  6. Sam Phen
    Sam Phen avatar
    10 posts
    Member since:
    Feb 2010

    Posted 30 Mar in reply to Shinu Link to this post

    Hi Telerik Team,

    With respect to the above question, when I set the width to one column, it is setting up the similar column width to all the other columns present in the GRID.

    I am using the latest telerik version 2016.1.113.45.

    Please suggest what needs to be done.

     

  7. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 30 Mar Link to this post

    Hello,

    When MasterTableView's TableLayout is switched to "Fixed" this will lead to all columns with no explicit width be equally wide and I suppose that this is the reason for the observed behavior. If you want to set specific column widths you need to set pixel widths to all grid columns.

    Regards,
    Pavlina
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  8. Sam Phen
    Sam Phen avatar
    10 posts
    Member since:
    Feb 2010

    Posted 01 Apr in reply to Pavlina Link to this post

    Hi Pavilina,

    Thanks for your quick response.

    I am not setting the tablelayout to 'fixed'. I think by default the layout is 'Auto'.

    <telerik:RadGrid ID="dgEscrow" runat="server" GridLines="None" EnableEmbeddedSkins="false" AutoGenerateColumns="false" ShowFooter="true" CssClass="esGridTable">
        <HeaderStyle Font-Bold="true" HorizontalAlign="Center" />
        <ClientSettings >
            <ClientEvents OnGridCreated="setScrollerDimensionsEscrow"   />
            <Scrolling AllowScroll="true" SaveScrollPosition="true" />        
        </ClientSettings>
    </telerik:RadGrid>

     

    Code behind:

     Protected Sub dgEscrow_PreRender(sender As Object, e As EventArgs) Handles dgEscrow.PreRender
            
            Dim gridCol As GridColumn = dgEscrow.MasterTableView.GetColumn("File #_String")
            gridCol.HeaderStyle.Width = Unit.Pixel(70)

        End Sub

     

    Let me know what else I need to do get this thing done.

     

     

  9. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 04 Apr Link to this post

    Hi,

    By design, the MasterTableView's TableLayout will be switched to "Fixed" if you are using static headers and at least one column width is set.

    Regards,
    Pavlina
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  10. Sam Phen
    Sam Phen avatar
    10 posts
    Member since:
    Feb 2010

    Posted 05 Apr in reply to Pavlina Link to this post

    So isn't there anyway by which we set width for few columns explicitly and the rest remains unchanged?

    Because once I am setting column width to one column, rest all columns are getting squeezed.

  11. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 07 Apr Link to this post

    Hello,

    As I said in one of the previous posts you need to set fixed width to all columns or leave them to auto size.

    Regards,
    Pavlina
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017