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

Linq to EF4 sorting/paging in RadGrid_NeedDataSource handler

1 Answer 70 Views
UI for ASP.NET AJAX in ASP.NET MVC
This is a migrated thread and some comments may be shown as answers.
Brooks
Top achievements
Rank 1
Brooks asked on 21 Mar 2012, 11:04 PM
I handle my sorting and paging explicitly in my entity framework calls from a NeedDataSource handler.

I persist the settings in session, and when I return to a page with a radgrid, I get the previous sort order and page correctly displayed...but I don't see how to highlight the sort column and its header to indicate the sort and sort direction.

I expected I could do so in the ItemDataBound handlers, but it eludes me! (I attempted to use a SortExpression, hoping it would at least trip the column indications even though there is no sorting to be done by it...no luck there either)

Can anyone help?

Thanks!


Oops! Not MVC...but RadGrid for AJAX

1 Answer, 1 is accepted

Sort by
0
Brooks
Top achievements
Rank 1
answered on 22 Mar 2012, 02:47 PM
I figured it out!

The GridSortExpression.FieldName property is a misnamed...it needs to match the SortExpression of the column in question...not the column DataField and not the column UniqueName.

For instance, to sort on this column:

<telerik:GridBoundColumn UniqueName="UserLastName" SortExpression="LastName,FirstName"
    HeaderAbbr="Last" HeaderText="Last Name" HeaderButtonType="TextButton"  DataField="LastName" />


My NeedDataSource handler does this:

...
else
if (_showPersistedPage)
GridSettings gs = Session.UserListSettings;
trg_UserList.DataSource = UberUserView.GetOrderedEntityUserList(_entityId, gs.SortExpression.Split(
','), gs.SortOrder, (int)gs.StartRowIndex, (int)gs.PageSize, true);
trg_UserList.CurrentPageIndex = (
int)gs.CurrentPageIndex;
trg_UserList.PageSize = (
int)gs.PageSize;

GridSortExpression exp =
new GridSortExpression();
exp.FieldName = gs.OrderBy;  //OrderBy is "LastName,FirstName"  It was failing when "LastName" or "UserLastName" was used.
exp.SetSortOrder(gs.OrderByDirection);
trg_UserList.MasterTableView.SortExpressions.AddSortExpression(exp);
...

To Telerik: this did not standout in the documentation!
Tags
UI for ASP.NET AJAX in ASP.NET MVC
Asked by
Brooks
Top achievements
Rank 1
Answers by
Brooks
Top achievements
Rank 1
Share this question
or