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

[Solved] SortCommand after NeedDataSource?

1 Answer 234 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dennis
Top achievements
Rank 1
Dennis asked on 05 Nov 2009, 09:33 AM
Hello,

I have a problem getting my sort operation to work properly. I have set up a grid with viewstate disabled.
The grid is used for viewing only and all row-actions are done clientside, so no need for the grid to remember its data

I use custom paging and sorting and in the NeedDataSource event I supply the grid with data.
The LINQ query in that event also applies sorting. When i have viewstate enabled the SortCommand event is fired before the needdatasource, so i can determine the desired sorting and fetch the data all at once in the NeedDataSource event.

But when i disable the viewstate, the SortCommand event is fired after the NeedDataSource event. So i need to execute the LINQ query twice.

So my question is this
Is there any way to determine on posback/callback if the grid is going to fire the SortCommand? and can i use that info to passthe sorting info to the query in the NeedDataSource event implementation?
Or is there a way to force the SortCommand to be fired before NeedDataSource at all times?
When i try to intercept the NeedDataSource event and execute it after the sortcommand, i get no data.

I use 2009 Q2 for Ajax

Thanks

1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 10 Nov 2009, 04:49 PM
Hello Dennis,

Indeed the sequence of events raised on sort operation with viewstate disabled conforms to the concepts listed in this section of the RadGrid documentation.

There are several options you might consider:
  - Instead of disabling the viewstate of control, store its viewstate in the Session as explained in the  article below:
http://www.telerik.com/help/aspnet-ajax/grdsavinggridviewstateinsession.html
 - Check the value of the e.RebindReason argument inside the NeedDataSource event handler. if it is 'PostbackViewStateNotPersisted" this means that the event is raised before the sort command gets executed.
- Construct your own logic which skips the first execution of the NeedDataSource event handler and sort the items before the second execution during the grid lifecycle takes place.

Kind regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Dennis
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Share this question
or