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

Column width of Dynamically generated columns

3 Answers 385 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Krutika
Top achievements
Rank 1
Krutika asked on 15 Nov 2012, 04:07 AM
I have a Radgrid and its columns are dynamically built at run time as it can have one to six columns.
It also has EditColumn and GridButton column and allowFiltering is set tot True.

I have two questions:

1)The radgrid seems to allocate equal width to each column.
If I try to allocate the width for editcolumn and Gridbutton column, the header/filter row doesnt seem to change accordingly.
How do I align the header/filter row with the rest of the rows?

2) As there are no templates used for columns, the edit buttons are displayed on the left side of the grid.
How can I move them to the right?



3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 15 Nov 2012, 04:49 AM
Hi,

You can set the width in ColumnCreated event and use the swap method to change the position of the columns.
C#:
protected void RadGrid1_ColumnCreated(object sender, Telerik.Web.UI.GridColumnCreatedEventArgs e)
{
  foreach (GridColumn col in RadGrid1.MasterTableView.AutoGeneratedColumns)
  {
    if (col.UniqueName == "UniqueName")
     {
        col.FilterControlWidth = Unit.Pixel(70);//for changing the width of the column
     }
  }
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
  RadGrid1.MasterTableView.SwapColumns(2, 7);//for changing positon of edit column
}

Thanks,
Shinu.
0
Krutika
Top achievements
Rank 1
answered on 15 Nov 2012, 04:20 PM
I tried both solutions.
1) The header row with filter control does not change width

2) In my radgrid, Data columns are autogenerated. But the Delete button and Edit button column are defined as columns in MasterTableView. Hence in my MasterTableView i have constant 2 columns, but in AutoGeneratedColumns I can anywhere from 1-6 columns. SwapColumn worked but it changes the complete order of the columns. That didnt help. Any other way?

how can I fix these issues?
0
Shinu
Top achievements
Rank 2
answered on 16 Nov 2012, 05:16 AM
Hi,

Unfortunately I cannot replicate the issue at my end. The following code worked as expected with AutoGeneratedColumns. Since GridExpandColumn and GridRowIndicatorColumn are always in front of data columns, the column indexs start at index 2. Hope this helps.
aspx:
<telerik:RadGrid AllowFilteringByColumn="true"  ID="RadGrid1" runat="server" DataSourceID="SqlDataSource2" AutoGenerateColumns="true" AutoGenerateDeleteColumn="true" onprerender="RadGrid1_PreRender" oncolumncreated="RadGrid1_ColumnCreated" >
</telerik:RadGrid>
C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
 RadGrid1.MasterTableView.SwapColumns(2, 8);
 RadGrid1.MasterTableView.SwapColumns(3, 7);
}
protected void RadGrid1_ColumnCreated(object sender, Telerik.Web.UI.GridColumnCreatedEventArgs e)
{
  foreach (GridColumn col in RadGrid1.MasterTableView.AutoGeneratedColumns)
  {
    if (col.UniqueName == "UniqueName")
     {
        col.FilterControlWidth = Unit.Pixel(70);
     }
  }
}

Thanks,
Shinu.
Tags
Grid
Asked by
Krutika
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Krutika
Top achievements
Rank 1
Share this question
or