Sorting on 'calculated' properties from the model

Sep 9, 2011 at 9:35 AM

See also the discussion GridDataExtensions ToGridData using nhibernate IQueryable.

When following the "documentation", "workarounds and fixes", "adding buttons inside the grid", I stumbled on a problem related with 'calculated' properties (= every property added to the model not existing in the database).

I added the extra property  'Actions' to my (nhibernate) model class, added all the other stuff and hit the refresh button in my browser.

Result an exception from the nhibernate query provider complaining about a query field not existing.

Why this field was sent to nhibernate?

Ok I was forgotten to set the .SetSortable(false) when adding the field to the columns. Hit refresh again and same error...

After debugging, I saw that jqgrid, even with the flag 'sortable: false', is setting the name of the first column in the sidx field. SearchModel is binding the value of this field to the searchmodel.SortColumnName, this field is applied to the query in the ApplyFilter Method and boum, the exception...

A bug in jqGrid? Am I missing some point?

The solution for the moment is not to put the 'Actions' as first column, but then the action buttons are not anymore in the first column. Lucky for me I don't show the Id column to my users, so the 'Actions' column is still the first column for the users.


Coordinator
Sep 9, 2011 at 4:03 PM

Strangely it does look like a jqGrid bug... I'll have to take a deeper look at the grid's code before I commit a workaround in the SearchModel.