views:

32

answers:

1

Hi,

I am just wondering whether it is possible to sort by 'combined columns' now (mvc contrib grid)?

I know it says here that it is not possible - at least at the time of posting at this site - but things might have changed in the meantime.

This is an example of a combined column in the view:

column.For(x => String.Format("{0} {1}", x.Proposer.LastName, x.Proposer.FirstName)).Named("Proposer");

Ideally I would like to sort by 'LastName' in this case.

Thanks.

Christian

PS: The main problem is that sort.Column is null for 'combined columns' when the GET request hits the controller. Perhaps there is a way to rectify this

+1  A: 

Unfortunately, not at this time, as you said.

Why not make a ViewModel that had the column you are creating? Since the sort code is dependent on the columns in the model (and not the client-side generated ones), it would be sortable when it posts back.

Jonathan Bates
Good argument for a view model which I am not using at the moment to keep things simple. Do you know how this affects 'lazy evaluation' (is this the right term?). This is what I am using at the moment: this.XService.GetAllXs().OrderBy(sort.Column, sort.Direction).AsPagination(page ?? 1, 10)) which I believe uses lazy evaluation (the back end uses NHibernate).
csetzkorn
I don't enough about NHibernate to be sure, but it would mostly depend on it and how it generates the set and processes the rest of the query. In my mind, you are adding another item to the process at the time you know it. You get the data, then paginating it. If you have to make a sort after pagination, wouldn't you have to re-paginate to get the proper results?So far, I like the results. I was going to use a JQuery grid solution, but one of the requirements was mobile phone functionality. Query string based sorts work better in this situation than js and that is why I went with it.
Jonathan Bates
are you refering to jqgrid. i like this very much and used it a lot. i want to avoid javascript though. i think the paging should take place after the sorting by the way.
csetzkorn
Yes, jqGrid. I do enjoy and would use it given the choice, but I think the mvc contrib grid is a fine alternative.
Jonathan Bates