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

Multi Sorting..

5 Answers 201 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dip
Top achievements
Rank 1
Dip asked on 29 Jan 2009, 04:26 AM
protected void SortCommand(object source, Telerik.Web.UI.GridSortCommandEventArgs e)
    {
     
        GridSortExpressionCollection ollection = new GridSortExpressionCollection();
       
        //ollection.AllowMultiColumnSorting=true;

        GridSortExpression S1=new GridSortExpression();
        S1.FieldName="ID";
        S1.SortOrder = GridSortOrder.Ascending;// SortDirection.Ascending;
        ollection.Add(S1);

        GridSortExpression S2=new GridSortExpression();
        S2.FieldName="Name";
        S2.SortOrder = GridSortOrder.Descending;
        ollection.Add(S2);
        ollection.AllowMultiColumnSorting=true;

        RadGrid1.MasterTableView.SortExpressions.AddSortExpression(ollection);     
       
    }

 Error      Argument '1': cannot convert from 'Telerik.Web.UI.GridSortExpressionCollection' to 'Telerik.Web.UI.GridSortExpression'    C:\Documents and Settings\DIP\My Documents\Visual Studio 2005\WebSites\sortGrid\Default.aspx.cs    105    68    C:\...\sortGrid\

I have set the RadGrid to be AllowmultipleSort=true....

What Am I doing wrong or missing?

Thanks,
DIP

5 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 29 Jan 2009, 08:13 AM
Hello Dip,

It seems that you are attempting to add GridSortExpressionCollection to the SortExpressions collection of the master table while only GridSortExpressions can be added to this collection (as the exception message states). Therefore, to avoid the error, you can add your two sort expressions directly to the SortExpressions collection of the master table.

Additionally, how to cancel the default sorting and apply your custom sort expressions you can see from this topic of the RadGrid documentation.

Kind regards,
Sebastian
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Dip
Top achievements
Rank 1
answered on 30 Jan 2009, 07:40 PM
Yes But how to how add a SortExpressionCollection ....Because the example only shows how to add a single expression where as the documentation says that we can add sortExpressionCollection..the reason why is ? It is because I have two grid and I have to have the same sort Expression..Would you also tell how to enforce Paging,sorting and filtering to another 2nd grid if they did paging,sorting and filtering on the first grid...  Just Like if the sorted One grid then 2nd grid should also be sorted ? Both have the same Datasource..
Please give an example if possible..

thanks,
DIP
0
Sebastian
Telerik team
answered on 02 Feb 2009, 05:04 PM
Hi Dip,

To synchronize both grid instances and apply the same sorting/filtering expressions to them as well as change their page index, you can use equivalent sort/filter expression and page index for the two grids. Further information on this subject can be gathered from the online help of the product in the topics listed below:

http://www.telerik.com/help/aspnet-ajax/grdsortingexpressions.html
http://www.telerik.com/help/aspnet-ajax/grdoperatewithfilterexpression.html
http://www.telerik.com/help/aspnet-ajax/grdbasicpaging.html

and from these demos:

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/sort/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/filtering/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/paging/defaultcs.aspx

Regards,
Sebastian
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Dip
Top achievements
Rank 1
answered on 04 Feb 2009, 03:01 AM
the Above link wasn't help at all..
Lets take an example for sorting..

when sorting on Grid1..I raise an event..

protected void Grid1_onsortCommand(object sender,GridItemEvents arg)
{
  foreach(GridsortExpression exp in e.item.ownerTableView.SortExpressions)
  {
    Grid2.masterTableView.SortExpressions.AddExpression(exp);
  }
Grid1.MasterTableView.Rebind();
Grid2.MasterTableView.Rebind();
}

Why doesn't this work...Please Clarify it..Please don't point to any more links...
Thanks,
DIP
0
Accepted
Sebastian
Telerik team
answered on 04 Feb 2009, 11:20 AM
Hello Dip,

I prepared a simple demo project which illustrates how to synchronize the sort expressions applied between two grids with the same data source. The logic should be executed inside the PreRender handlers of the grids.

Here are the relevant code snippets:

            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
                <AjaxSettings> 
                    <telerik:AjaxSetting AjaxControlID="RadGrid1">  
                        <UpdatedControls> 
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                             <telerik:AjaxUpdatedControl ControlID="RadGrid2" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting> 
                    <telerik:AjaxSetting AjaxControlID="RadGrid2">  
                        <UpdatedControls> 
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                             <telerik:AjaxUpdatedControl ControlID="RadGrid2" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting> 
                </AjaxSettings> 
            </telerik:RadAjaxManager> 
            <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Height="75px" 
                Width="75px" Transparency="20">  
                <img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>' 
                    style="border: 0;" /> 
            </telerik:RadAjaxLoadingPanel> 
            <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" AllowSorting="True" 
                Skin="Office2007" ShowStatusBar="true" GridLines="None" Width="95%" OnPreRender="RadGrid1_PreRender">  
                <MasterTableView Width="100%" AllowMultiColumnSorting="true" /> 
                <SortingSettings SortedBackColor="Azure" /> 
            </telerik:RadGrid> 
            <telerik:RadGrid ID="RadGrid2" runat="server" DataSourceID="SqlDataSource1" AllowSorting="True" 
                Skin="Office2007" ShowStatusBar="true" GridLines="None" Width="95%" OnPreRender="RadGrid2_PreRender">  
                <MasterTableView Width="100%" AllowMultiColumnSorting="true" /> 
                <SortingSettings SortedBackColor="Azure" /> 
            </telerik:RadGrid> 
            <br /> 
            <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" 
                ProviderName="System.Data.SqlClient" SelectCommand="SELECT TOP 10 CustomerID, CompanyName, ContactName, ContactTitle, Address, PostalCode FROM Customers" 
                runat="server"></asp:SqlDataSource> 

    protected void RadGrid1_PreRender(object sender, EventArgs e)  
    {  
        foreach (GridSortExpression exp in RadGrid1.MasterTableView.SortExpressions)  
        {  
            RadGrid2.MasterTableView.SortExpressions.AddSortExpression(exp);  
        }  
        RadGrid2.MasterTableView.Rebind();  
    }  
    protected void RadGrid2_PreRender(object sender, EventArgs e)  
    {  
        foreach (GridSortExpression exp in RadGrid2.MasterTableView.SortExpressions)  
        {  
            RadGrid1.MasterTableView.SortExpressions.AddSortExpression(exp);  
        }  
        RadGrid1.MasterTableView.Rebind();  
    } 

Regards,
Sebastian
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Dip
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Dip
Top achievements
Rank 1
Share this question
or