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

RadGrid change column order when using combination of auto generated and static columns

1 Answer 495 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Randy
Top achievements
Rank 1
Randy asked on 24 Jul 2013, 01:55 PM
So I am searching for a good example that shows the best way to change the order of columns on the server-side.  I have a grid that has some static columns defined in the ascx fileself.  Then I am using AutoGenerate to add a number of additional columns.  I want two of the static defined columns I create to be placed at the end (right).  For example, I have a custom Attachment column that needs to be placed last.  From the posts I read, it sounds like I should be using SwapColumns to do this.  It would really be nice if there were a MoveTo method instead of having to rely on Swapping columns down the list. 

Thanks, R

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 29 Jul 2013, 01:07 PM
Hello Randy,

There are several possible ways to achieve the requested functionality:
  • Using OrderIndex:
Copy Code
Copy Code
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("DragDropColumn") as GridColumn;
        column.OrderIndex = RadGrid1.MasterTableView.RenderColumns.Length;
        RadGrid1.MasterTableView.Rebind();
    }
}

  • Swap command on the server:
http://www.telerik.com/help/aspnet-ajax/overload_telerik_web_ui_gridtableview_swapcolumns.html
  • Swap command on the client:
http://www.telerik.com/help/aspnet-ajax/grid-gridtableview-swapcolumns.html
  • Reorder on the client:
http://www.telerik.com/help/aspnet-ajax/grid-gridtableview-reordercolumns-index1-index2.html

To understand the difference between reordering and swapping columns on client, please check out the following topic:
http://www.telerik.com/help/aspnet-ajax/grid-reordering-columns.html

I hope this will prove helpful. Please choose the approach most suitable to your specific requirements and let me know about the result.

Regards,
Eyup
Telerik
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 the blog feed now.
Tags
Grid
Asked by
Randy
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or