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

[Solved] Multi Column sorting in radgrid

4 Answers 541 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Balajee Vasudevan
Top achievements
Rank 1
Balajee Vasudevan asked on 05 Jan 2010, 04:55 AM

Hi, 
 
I want to implement the multicolumn sorting for radgrid placed in the user control .i have some default sorting (multi column) depends on the page where the user control is used . so , i have used the following code to set the default sorting in the user control ,

<

 

SortExpressions>

 

 

<telerik:GridSortExpression FieldName="SupplierDueDate" SortOrder="Ascending" />

 

 

<telerik:GridSortExpression FieldName="CountyName" SortOrder="Ascending" />

 

 

<telerik:GridSortExpression FieldName="Municipality" SortOrder="Ascending" />

 

 

<telerik:GridSortExpression FieldName="PostalCode" SortOrder="Ascending" />

 

 

<telerik:GridSortExpression FieldName="CooperativeHousing" SortOrder="Ascending" />

 

</

 

SortExpressions>

Then i planned to change these settings(i.e) the columns  programmatically in the server side (to overrride these settings based on the page) like these:

 

 

case "MyOrders":

 

 

 

 

 

 

 

 

 

this.grdOrderList.MasterTableView.SortExpressions.Clear();

 

sortExpr =

new GridSortExpression();

 

sortExpr.FieldName =

"CreatedTime";

 

sortExpr.SortOrder =

GridSortOrder.Ascending;

 

 

this.grdOrderList.MasterTableView.SortExpressions.AddSortExpression(sortExpr);

 

 

break;

 

 

But this seems not working ... since using the sortExpression.Clear() i see a small command button in the headers of the column(just beside the column name ) .... please tell  me where im going wrong with the possible solution to implement the above 

thanks in advance,
Balajee


 



4 Answers, 1 is accepted

Sort by
0
Johny
Top achievements
Rank 1
answered on 05 Jan 2010, 12:14 PM
Hello Balajee,

Have you tried rebinding the grid after setting the sort expression in the code-behind? In this documentation link such approach is used:

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

I hope this helps.
Johny



0
Balajee Vasudevan
Top achievements
Rank 1
answered on 06 Jan 2010, 05:46 AM
Hi Johny,

yes, that played the trick.. now the code works absolutely fine...

Also, can you tell me how do i perform multiple column sorting programattically 
for example

if i want to set multicolumn sorting like this 

this

 

.grdOrderList.MasterTableView.SortExpressions.Clear();

 

sortExpr =

new GridSortExpression();

 

sortExpr.FieldName =

"CreatedTime";

 

sortExpr.FieldName =

"EmpName";

 

sortExpr.SortOrder =

GridSortOrder.Ascending;

 

 

this.grdOrderList.MasterTableView.SortExpressions.AddSortExpression(sortExpr);

 

 

this.grdOrderList.MasterTableView.Rebind();

The collection doesnt seem to hold both the values ...but only the latest "EmpName" ....

thanks in advance,
Balajee

 

0
Johny
Top achievements
Rank 1
answered on 06 Jan 2010, 07:53 AM
Hi Balajee,

You will need to create a new sortExpression object for every field that you want sorted. So you can try the following modification:

this.grdOrderList.MasterTableView.SortExpressions.Clear(); 
        sortExpr = new GridSortExpression(); 
        sortExpr.FieldName = "CreatedTime"
        sortExpr.SortOrder = GridSortOrder.Ascending; 
        this.grdOrderList.MasterTableView.SortExpressions.AddSortExpression(sortExpr); 
 
        sortExpr = new GridSortExpression(); 
        sortExpr.FieldName = "EmpName"
        sortExpr.SortOrder = GridSortOrder.Ascending; 
        this.grdOrderList.MasterTableView.SortExpressions.AddSortExpression(sortExpr); 
 
        this.grdOrderList.MasterTableView.Rebind(); 

Thanks
Johny


0
Balajee Vasudevan
Top achievements
Rank 1
answered on 06 Jan 2010, 08:38 AM
Hi,

Thanks for the solution . this works fine .


Thanks,
Balajee
Tags
Grid
Asked by
Balajee Vasudevan
Top achievements
Rank 1
Answers by
Johny
Top achievements
Rank 1
Balajee Vasudevan
Top achievements
Rank 1
Share this question
or