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

align column content and auto fit column

9 Answers 251 Views
Grid
This is a migrated thread and some comments may be shown as answers.
appdev
Top achievements
Rank 1
appdev asked on 02 Jun 2011, 10:28 PM
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

9 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 03 Jun 2011, 07:35 AM
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.
0
appdev
Top achievements
Rank 1
answered on 03 Jun 2011, 02:07 PM
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.
0
Accepted
Shinu
Top achievements
Rank 2
answered on 06 Jun 2011, 08:54 AM
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.
0
Sam Phen
Top achievements
Rank 1
answered on 30 Mar 2016, 06:48 AM

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.

 

0
Pavlina
Telerik team
answered on 30 Mar 2016, 08:55 AM
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.
0
Sam Phen
Top achievements
Rank 1
answered on 01 Apr 2016, 11:04 AM

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.

 

 

0
Pavlina
Telerik team
answered on 04 Apr 2016, 02:10 PM
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.
0
Sam Phen
Top achievements
Rank 1
answered on 05 Apr 2016, 06:20 AM

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.

0
Pavlina
Telerik team
answered on 07 Apr 2016, 03:52 PM
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.
Tags
Grid
Asked by
appdev
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
appdev
Top achievements
Rank 1
Sam Phen
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or