I am using jqgrid on EF4 MVC3 (C#). I based search on this @Oleg ‘s solution, which works fine and fits for my needs.
I have the following columns defined in my grid:
...
{ name: 'Stato', index: 'StatoTicketID', width: 20, align: 'left', sorttype: 'int', searchoptions: { sopt: ['eq']} },
{ name: 'StatoTicketID', index: 'StatoTicketID', width: 20, align: 'left', sorttype: 'int', hidden: true, searchoptions: { sopt: ['eq']} },
...
As you can see, the column Stato is ordered by the index StatoTicketID (hidden integer field) and ordering works fine.
PROBLEM
When I try to search a value of Stato, the filter is passed on index StatoTicketID as string, while I’d like to search by Stato values. So I get an exception inside the controller which specifies that I cannot convert String type to Int32.
Does exist a way to specify on which column apply search, when index is on a different column, like in my case?
EDIT & WORKAROUND:
For now I solved my problem with the following workaround.
(inside foreach (Rule rule in rules) of FilterObjectSet by Oleg)
....
if (rule.field == "StatoTicketID")
{
rule.field = "StatoTicket.Stato";
propertyInfo = typeof(T).GetProperty("stringfield"); // where stringfield is a text type column of my model
}
I realize very well that is not an elegant solution, I expect a kind response by you, to know how to implement the required behaviour directly from jqGrid, please.
Thanks in advance
It seems to me that you chosen too complex way. I would just send to the client (to the jqGrid) only the
Statoand have toStatoTicketIDat all. From the design point of your theStatoTicketIDis the part of the server implementation and the client should not depend from this.If you have Unique Constrain (or unique index) on
Statocolumn of theStatoTicketstable you would very quickly find theStatoTicketIDwhenever you as need. So the jqGrid can contain and “know” only aboutStatoand have no information about theStatoTicketIDas the implementation detail.One more way to solve the problem is the usage of
formatter: 'select'in the columnStato. It’s important to understand that in the case the mapping betweenStatotext and theStatoTicketIDshould be loaded before the grid is created. In the case theStatocolumn should have the properties likeOne can’t use
dataUrlin the case instead ofvaluein theeditoptions.As the result you will be able to fill column
Statowith theStatoTicketIDdata, but the corresponding texts will displayed by jqGrid.I recommend you better to implement the first way with pure
Statotext. All the problems you would be able to solve only on the server part.