Change Order of Column in RadGrid

7 posts, 0 answers
  1. Erick
    Erick avatar
    8 posts
    Member since:
    May 2015

    Posted 22 May 2015 Link to this post

    Hello,

     

    I have a RadGrid that is displayed inside another RadGrid through NestedViewTemplate. This RadGrid contains auto generated columns, and one GridTemplateColumn that I have added to calculate the sum of two auto generated columns. I would like to change the location of this column, currently it shows as the first column in the RadGrid.

     

    This is what the RadGrid looks like:

    <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="false" Width="100%"
        AllowFilteringByColumn="true" AllowSorting="true" EnableHeaderContextMenu="true" EnableLinqExpressions="false"
        EnableHeaderContextFilterMenu="true" Skin="Windows7" ShowFooter="true" OnItemDataBound="RadGrid1_ItemDataBound"
        OnNeedDataSource="RadGrid1_NeedDataSource" OnPreRender="RadGrid1_PreRender" OnColumnCreated="RadGrid1_ColumnCreated" >
        <MasterTableView EnableNoRecordsTemplate="true" ShowHeadersWhenNoRecords="true" AutoGenerateColumns="true" IsFilterItemExpanded="false" AllowFilteringByColumn="true" TableLayout="Auto">
        <NoRecordsTemplate>
            <div style="width:100%;text-align:center;">
                No are no records to display!
            </div>
        </NoRecordsTemplate>
        <Columns>
            <telerik:GridTemplateColumn UniqueName="Total" HeaderText="Total" SortExpression="Total">
                                                            
            </telerik:GridTemplateColumn>
        </Columns>
        <FooterStyle Font-Bold="true" Font-Size="Large" />
        </MasterTableView>
    </telerik:RadGrid>

     

    And the PreRender contains:

    (sender as RadGrid).MasterTableView.GetColumn("Total").OrderIndex = 2;

     

    But it still is being displayed as first.

  2. Erick
    Erick avatar
    8 posts
    Member since:
    May 2015

    Posted 25 May 2015 in reply to Erick Link to this post

    Nothing?
  3. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 27 May 2015 Link to this post

    Hello,

    Try to call Rebind() after changing the ColumnIndex like this:
    protected void Page_PreRender(object sender, EventArgs e)
    {
         
        foreach (Telerik.Web.UI.GridColumn col in RadGrid1.MasterTableView.RenderColumns) {
            if (col.UniqueName.Equals("Total")) {
                col.OrderIndex = 2;
            } else if (col.UniqueName.Equals("Region")) {
                col.OrderIndex = 6;
            } else if (col.UniqueName.Equals("ContactName")) {
                col.OrderIndex = 5;
     
            }
     
     
        }
        RadGrid1.Rebind();
    }


    Regards,
    Maria Ilieva
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  4. Erick
    Erick avatar
    8 posts
    Member since:
    May 2015

    Posted 27 May 2015 in reply to Maria Ilieva Link to this post

    Hi Maria,

     

    Thanks for the reply.

     

    Do I have to set the order for each Column? Could I just do it for one?

     

    Also, is the rebind necessary? If I do a Rebind in the PreRender then my totals in the footer are doubled, because it binds the data twice (Calls ItemDataBound twice)

  5. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 01 Jun 2015 Link to this post

    Hi Erick,

    You can set the OrderIndex for just one column and the other will keep their places based ion their order in the DB. You should call rebind after changing the OrderIndex as the index should be updated in the DB.

    Regards,
    Maria Ilieva
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Erick
    Erick avatar
    8 posts
    Member since:
    May 2015

    Posted 08 Jun 2015 Link to this post

    So after doing the rebind, how do I deal with the totals being double what they should be?

     

    If I have two rows, one = 5, two = 5...Total should be 10, but when I use the REBIND, I get 20.

  7. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 11 Jun 2015 Link to this post

    Hello Erik,

    Try to rebind the MasterTableView instead of the Grid , like this:
    RadGrid1.MasterTableView.Rebind();


    Regards,
    Maria Ilieva
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top