Is it possible to send field type while filtering in jqgrid?
my jqgrid client app sends this:
{ "groupOp":"AND", "rules":[{"field":"customernumber", "op":"ge", "data":"200"}]}
is it possible to make jqgrid send even the field type sth like
{ "groupOp":"AND", "rules":[{"field":"customernumber", "type":开发者_如何学编程"int":,"op":"ge", "data":"200"}]}
First of all the feature which you need isn't exist in jqGrid. Moreover the problem is that jqGrid has no type information about the column data which you can directly use. jqGrid has only settings like sorttype used for the local sorting only or formatter and edittype. Additionally exist stype which can be either "text" or "select". So there are no data type for the column. Having new datatype
property could be in my opinion an interesting feature for the future versions of jqGrid.
Now about the reality. If you know which from the column settings are the datatype in your case (sorttype
, formatter
or edittype
) you can extend the information from the filter
parameter of the postData
with the information which you need. To implement this you can use serializeGridData for example. Inside of the serializeGridData event handle you can examine the filter parameter. If it exist, you can convert it to the object with respect of jQuery.parseJSON the resulting filter object you can easy extend with additional property type
in the rules
array. To do this you can match the field
property of the item of the rules
array with the edittype
(or sorttype
, formatter
) property of colModel
. By the way you can easy get reference to the colModel
from the grid with $("list").jqGrid('getGridParam','colModel')
. After you modified the filter
object you can convert it back to the JSON with JSON.stringify function from the json2.js and place it to the postData
with will be sent to the server.
All what I explain above is only a rough schema, but it can relatively easy be implemented.
I had this same need a short time ago and I overcomed it by passing that "knowledge" server side.
The problem: jqGrid doesn't support what you need, it doesn't care about the type of the field, and it does make sense in a way that enforcing this could cause you other problems. Implementing your own serialization mechanism looks too complex and will probably give you some problems on future updates on the control. For me this solution was to be used everywhere as my apps usually have a lot of search enabled grids, I didn't want to override any of the default grid's functionalities to avoid problems on the future control updates.
My solution: What jqGrid gives you is the column name, the filter value and the operation. Server side you can get the type of the column by its column name so you really don't need this information sailling around in the wire. Put this knowledge on the service or controller or where ever you're calling to perform the serach request and everything should be fine.
Short note: In my case I'm using .net Entity Framework so I'm getting the column type from the ORM object property type.
Cheers! Alex
精彩评论