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

SEO Paging, need SEO Sorting too

1 Answer 37 Views
Grid
This is a migrated thread and some comments may be shown as answers.
tom
Top achievements
Rank 1
tom asked on 18 Dec 2008, 03:44 PM
The SEO Paging works great, but after sorting the grid then paging, the sort is not retained.

What is the best way to handle this?

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 22 Dec 2008, 08:38 AM
Hello tom,

The issue that you describe is not a bug, but rather expected behavior, because with SEO paging enabled, when you go to other page, the grid is created from scratch. In other words when you choose some page from the grid pager or open the page with URL, which contains the number of the page you want to open, the grid behaves in the same way.

We suggest you keep the value of SortExpressions property in a Cache or Session variable for example, and to retrieve the value from this variable when the OnInit event is fired. In it you can assign the fetched value to the SortExpressions property of the grid, to avoid explicit rebind to reflect the change.

Here is a code snippet which shows how to get the SortExpressions value:
//OnPreRender event get SortExpression value and save it in Session variable 
void RadGridMain_PreRender(object sender, EventArgs e) 
if (RadGridMain.MasterTableView.SortExpressions.Count > 0) 
Session["SortingString"] = RadGridMain.MasterTableView.SortExpressions.GetSortString(); 

Then on OnInit event populate the SortExpressions collection:
protected override void OnInit(EventArgs e) 
base.OnInit(e); 
 
if (Session["SortingString"] != null
string[] sortExpressions = Session["SortingString"].ToString().Split(','); 
foreach (string epxression in sortExpressions) 
RadGridMain.MasterTableView.SortExpressions.AddSortExpression(epxression); 

As you noticed I split the SortingString, because if multi-column sorting is allowed, all sort expressions will be enumerated divided by comma. After that each separate sort expression is added to the SortExpressions collection of the master table.

Kind regards,
Georgi Krustev
the Telerik team

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