I think that the main problem which you have is that filters
parameter will be send by jqGrid in another way as all other parameters. You can define it as string
and make conversion to FilterModel
from JSON manually (using JsonConvert.DeserializeObject<FilterModel>(filters)
of Newtonsoft.Json
or using serializer.Deserialize<FilterModel>(filters)
, where JavaScriptSerializer serializer = new JavaScriptSerializer();
). It seems to me the most easy way. You can of cause use custom model binder of MVC, but you will have at the end the same results.
Alternatively you can try to change the value of filters
parameter which send jqGrid
serializeGridData: function (postData) {
var dataToSend = $.extend({}, postData); // make copy
if (dataToSend.filters) {
dataToSend.filters = $.parseJSON(postData.filters);
}
// the last statement can be not needed and one should just use
// return dataToSend;
// instead. If one do convert the data to JSON as in the line below
// one should use ajaxGridOptions: { contentType: "application/json" }
// option of jqGrid to set the corresponding ContentType HTTP header
return JSON.stringify(dataToSend);
}
I don't tested the above code, but I think that it could work.
Additionally I want post some common remarks.
You need implement server side paring and filtering only for really large dataset. In case of having less as 1000 rows of data for example I prefer to use loadone: true
parameter and return all data at one to the client. Filtering of such set of data on the client side work really good (and even more quickly as server side filtering) and you will need don't write any server code for filtering. So: don't try to use sever side filtering on small dataset.
The next remark. If you use only Advanced Searching then you can remove searchField
, searchOper
and searchString
parameters. "Simple" searching is legacy model.
The next remark: default names of parameters which send jqGrid is not the best: sidx
, sord
, _search
. One can use prmNames
parameter of jqGrid to rename almost all parameters send by jqGrid. For example if you would use prmNames: {sort: "sortIndex", order: "sortDirection", search: "isSearching"}
you can rename sidx
to sortIndex
, sord
to sortDirection
and _search
to isSearching
in SearchModel
.
The last remark. If you really need to implement server side filtering of data you can consider to implement the full model described here. It includes groups
part together with rules
. The groups
part will be filled if you would use multipleGroup: true
option together with multipleSearch: true
.