jqGrid使用multipleSearch产生的查询条件filters分析
2013-09-30 15:05
302 查看
This is a tutorial that shows how to handle a JSON Object that is received in a
Struts2 Action. This Example is based on the
Struts2 Grid Showcase for the
Struts2 jQuery Plugin with Grid Extension.
1). First we need to enable the Multi Search Feature for the Grid Component.
Now we can use the multiple search feature like this.
![](http://i1.wp.com/www.jgeppert.com/struts2-jquery/jqgrid_multiple_search.jpg)
2.) After this we need a String propertyfilter in our Struts2 Action.
3.) Now we receive a JSON Object when we use the Search in the Navigator of the Grid. The JSON looks like this example.
4.) To work with this, we need to serialize this as a JSONObject.
5.) Now we can get the value from the JSON Object. First we get the parameter groupOp.
6.) Now we need the rules as JSONArray and the size of this array.
7.) In a simple for-loop we can get the values of the rule.
Now you should be able to use this values to build a custom SQL query or build an hibernate criteria.
http://code.google.com/p/struts2-jquery/wiki/
Struts2 Action. This Example is based on the
Struts2 Grid Showcase for the
Struts2 jQuery Plugin with Grid Extension.
1). First we need to enable the Multi Search Feature for the Grid Component.
< sjg :grid id="customerstable" ... navigatorSearch="true" navigatorSearchOptions="{multipleSearch:true}" ... > |
![](http://i1.wp.com/www.jgeppert.com/struts2-jquery/jqgrid_multiple_search.jpg)
2.) After this we need a String propertyfilter in our Struts2 Action.
private String filters; public void setFilters(String filters) { this.filters = filters; } |
{ "groupOp":"AND", "rules":[ { "field":"customernumber", "op":"lt", "data":"200" } , { "field":"country", "op":"eq", "data":"USA" } ] } |
JSONObject jsonFilter = (JSONObject) JSONSerializer.toJSON( filters ); |
String groupOp = jsonFilter.getString("groupOp"); log.debug("groupOp :" + groupOp); |
JSONArray rules = jsonFilter.getJSONArray("rules"); int rulesCount = JSONArray.getDimensions(rules)[0]; log.debug("Count Rules :" + rulesCount); |
for (int i = 0; i < rulesCount; i++) { JSONObject rule = rules.getJSONObject(i); log.debug("field :" + rule.getString("field")); log.debug("op :" + rule.getString("op")); log.debug("data :" + rule.getString("data")); } |
http://code.google.com/p/struts2-jquery/wiki/
相关文章推荐
- Linq使用Group By分析 Entity Framework 使用注意:Where查询条件中用到的关联实体不需要Include
- jqGrid————使用心得 合计、默认查询条件、自适应、序号等
- JqGrid往后台传递查询参数使用Filters时的参数类型转换.
- Hibernate 使用 HQL 查询 使用List 作为查询条件的注意(也是相当于别名查询)
- Yii中使用CDbCriteria方法来进行查询的各种条件
- mysql慢查询日志分析工具使用
- 在使用ibatis实现多条件模糊查询的语句
- 使用Hibernate条件查询时,无法识别对象属性
- Thinkphp 查询条件 and 和 or同时使用即复合查询
- c语言学习笔记(12)条件编译使用分析
- 【SSH项目实战】国税协同平台-24.条件查询分析与实现
- Oracle使用in关键字查询时,按照条件输出查询结果
- Ruby on Rails,使用where方法对持久化对象进行条件查询
- 使用反射让linq实现动态查询, 类似拼接sql语句的where 条件
- 使用Oracle外部表来查询分析警告日志
- Hibernate 使用Disjunction动态添加查询条件
- 计算时使用浮点数产生误差的原因分析
- 使用Sql按日期条件查询
- oracle 使用explain plan分析查询语句
- struts中使用form保持查询条件不变