Programatically Move first column to last without swap

6 posts, 1 answers
  1. Mike
    Mike avatar
    9 posts
    Member since:
    Jul 2008

    Posted 28 Feb 2010 Link to this post

    Hi all,

    I have a radgrid that uses a combination of Autogenerated columns (because the columns cannot be identified until the query is created) and gridtemplate columns.

    My main problem is that the gridtemplate columns are first before the autogenerated columns. I'd like to find a way to make the gridtemplate columns be last.


    I tried to attempt this using MasterTableView.SwapColumns but i dont want to swap. Instead i just want to move all gridtemplate columns to be last. Im attempting this code in my radgrid_prerender. 

    Also the order that the autogenerated columns are created must remain in that order because the sql query is built based on what the user has selected as fields to display.

    Example ("select field1, field2, field3, field4 from table")  it should stay in that order for autogenerated columns without having to swap any.

    Hope this makes sense

    thank you,

    Mike
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 01 Mar 2010 Link to this post

    Hello Mike,

    You can set the OrderIndex property of the columns, instead of using SwapColumns(). Set the OrderIndex for each columns from code behind and call Rebind() method of grid.

    I hope the documentation will be helpful to you.
    Reordering columns

    Here is the code that I tried for same kind of scenario:
     
        protected void RadGrid1_PreRender(object sender, EventArgs e) 
        { 
            GridColumn c = RadGrid1.MasterTableView.GetColumnSafe("TemplateColumnUniqueName"); 
            if (c != null
            { 
                int total = RadGrid1.MasterTableView.RenderColumns.Count() - 2; 
                for (int i = total; i >= 2; i--) 
                { 
                    RadGrid1.MasterTableView.RenderColumns[i + 1].OrderIndex = i - 1; 
                } 
                c.OrderIndex = total + 1; 
            } 
            RadGrid1.MasterTableView.Rebind(); 
        } 

    [Note: When using the OrderIndex property to reorder columns, make sure that you assign values so that no two columns have the same index and no index is omitted.]

    Regards,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mike
    Mike avatar
    9 posts
    Member since:
    Jul 2008

    Posted 01 Mar 2010 Link to this post

    Thank you for your reply,

     The version of Telerik Im using is 2008.2.723.20.

    RadGrid1.MasterTableView.RenderColumns.Count does not seem to be available. I wonder if this is only in latest versions.

    Thanks for the link for the documentation I did look at it previously and saw the orderindex but I could not find a way to loop through the autogenerated columns to re-order their indexes.  Only the gridtemplate columns were part of the  gridcolumncollection for the sample code

     

     

     

    Dim cols As GridColumnCollection = rgAdhocReport.MasterTableView.Columns  
    Dim c As GridColumn = cols.FindByUniqueName("ACTIONS")  
            If Not IsNothing(c) Then  
                Dim start As Integer = c.OrderIndex  
                Dim i As Integer = start 
                While i < cols.Count 
                    c = cols(i)  
                    If i < cols.Count - 1 Then  
                        c.OrderIndex = i + 1  
                    Else  
                        c.OrderIndex = start 
                    End If  
                    System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)  
                End While  
            End If 

     

  5. Mike
    Mike avatar
    9 posts
    Member since:
    Jul 2008

    Posted 01 Mar 2010 Link to this post

    Update: I tried using MasterTableView.RenderColumns.Length to get the count.  This seems to be working. Thank you
  6. Gayathri
    Gayathri avatar
    25 posts
    Member since:
    Oct 2014

    Posted 18 Sep 2015 in reply to Shinu Link to this post

    Hi Shinu,

     

    But Rebind in Prerender does not work. Any other alternate suggestion please?

     

    -Thanks

    Gayathri

  7. Gayathri
    Gayathri avatar
    25 posts
    Member since:
    Oct 2014

    Posted 18 Sep 2015 in reply to Shinu Link to this post

    My problem is as follows.

    I have 5 columns added at design time. A,B,C,D,E(These are Gridboundcolumn)

    and finally i am adding H as gridbutton column with delete button with delete image. all are done nicely. But F and G are added dynamically and H is placed in between this F & G which i want to move after G.

    Unfortunately reordering in prerender and rebind of the grid does not work .

    Please suggest.

    -Thanks

     

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017