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

Change Order of Column in RadGrid

6 Answers 1062 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Erick
Top achievements
Rank 1
Erick asked on 22 May 2015, 06:09 PM

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.

6 Answers, 1 is accepted

Sort by
0
Erick
Top achievements
Rank 1
answered on 25 May 2015, 01:57 PM
Nothing?
0
Maria Ilieva
Telerik team
answered on 27 May 2015, 09:57 AM
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
0
Erick
Top achievements
Rank 1
answered on 27 May 2015, 06:47 PM

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)

0
Maria Ilieva
Telerik team
answered on 01 Jun 2015, 11:14 AM
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
0
Erick
Top achievements
Rank 1
answered on 08 Jun 2015, 02:48 PM

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.

0
Maria Ilieva
Telerik team
answered on 11 Jun 2015, 10:06 AM
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
Tags
Grid
Asked by
Erick
Top achievements
Rank 1
Answers by
Erick
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or