描述:顾名思义,即按照单个表头进行排序,但是允许多个表头都是排序字段,只是传值时只传当前点击的表头
1. 后端配置
需要在后台接收sidx和sord,sidx是固定参数,其值为所点击的列名,sord也为固定参数,其为排序方式,升序还是降序
可以将这两个字段单独在controller方法中去接受,也可以写到实体类中作为字段去接收,本例中将这两个参数写到实体类中
sql中order by时需要用动态参数去取值
controller代码如下:
@RequestMapping(value = "/selectGuideJudgeStatisticsForPage.json", method = RequestMethod.POST) public @ResponseBody IPageModule selectGuideJudgeStatisticsForPage(HttpServletRequest request, HttpServletResponse response, GuideInfo guideInfo,String sord,String sidx) { IPageModule pageModule = null; try { System.out.println(sord); System.out.println(sidx); pageModule= guideJudgeService.selectGuideJudgeStatisticsForPage(guideInfo); } catch(Exception e) { e.printStackTrace(); } return pageModule; }map-*.xml代码部分如下:
ORDER BY <choose> <when test="sidx != null and sidx != ''"> ${sidx} ${sord} </when> <otherwise> T.NAME </otherwise> </choose>需要注意的是此处取值使用$,不能使用#,只需要判断sidx是否有值即可,因为sord一直都有值,如果不需要默认排序,也可以这样写:
<if test="sidx != null and sidx != ''"> ORDER BY ${sidx} ${sord} </if>2. 前端配置
multiSort属性设置为false:multiSort: false,也可以不写。
colModel属性对应列设置排序参数,如下:
colModel: [ {name: 'guideId', index: 'guideId', width: 0, sortable:false, align:'left', hidden:true, key:true}, {name: 'name', index: 'name', width: 20, sortable:false,align:'left'}, {name: 'phone', index: 'phone', width: 25, sortable:false,align:'center'}, {name: 'avgJudgeScore', index: 'avgJudgeScore', width: 25, dataType: "float", sortable: true,align:'center'}, {name: 'judgeCounts', index: 'judgeCounts', width: 25, dataType: "int", sortable: true,align:'center'} ],这两个属性:dataType: “int”, sortable: true
描述:即可以按照多个表头进行联合排序
1. 后端配置
与单级排序的写法上没有区别2. 前端配置
与单级排序的区别:添加multiSort或者更改multiSort属性为true即可