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

[Solved] Synchronize sorting across multiple RadGrids

2 Answers 159 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dean
Top achievements
Rank 1
Dean asked on 06 May 2009, 09:17 PM
Hello,

I think I am trying to accomplish something fairly simple but I can't seem to figure it out.  Hopefully somebody can point me in the right direction.

I have 5 RadGrids within one System.Web.UI.UserControl on an ASPX page.  All 5 RadGrids share the same structure in terms of columns and options by using the same Skin (SkinID="") in my Theme.  They also all share the same DataSource that is a DataView based on a DataTable from a business object.  I am using OnNeedDataSource so that RadGrid can do the binding for me when necessary.

Now what I would like to do, is have all 5 RadGrids remain synchronized in terms of sorting.  So, if the user clicks a column header to sort one of the RadGrids, they all get sorted based on what the user clicked.  So far, I have not been able to figure it out.

Any ideas?

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 07 May 2009, 04:02 AM
Hi Dean,

Go through the following forum link which discusses a similar requirement. You may alter the logic accordingly.
synchronise sorting with second grid

Regards
Shinu
0
Dean
Top achievements
Rank 1
answered on 07 May 2009, 11:15 AM
Thanks, Shinu.

I stumbled across the answer shortly after my original post.  It worked like a charm!

For what it's worth:

 

 

protected void RadGrid_SortCommand(object source, GridSortCommandEventArgs e)  
{  
        // reference RadGrid raising this event  
        RadGrid sourceGrid = (RadGrid)source;  
 
        // create the new sort expression  
        GridSortExpression sortExp = new GridSortExpression();  
        sortExp.FieldName = e.SortExpression;  
        sortExp.SortOrder = e.NewSortOrder;  
          
        // array of RadGrid objects to synch sort  
        RadGrid[] grids = { rg1, rg2, rg3, rg4, rg5 };  
 
        // add new sorting to grids and rebind  
        foreach (RadGrid grid in grids)  
        {  
            if (!sourceGrid.Equals(grid))  
            {  
                grid.MasterTableView.SortExpressions.AddSortExpression(sortExp);  
                grid.MasterTableView.Rebind();  
            }  
        }  

Tags
Grid
Asked by
Dean
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Dean
Top achievements
Rank 1
Share this question
or