jqGrid表头排序功能

1.单级排序

描述:顾名思义,即按照单个表头进行排序,但是允许多个表头都是排序字段,只是传值时只传当前点击的表头

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

2.多级排序

描述:即可以按照多个表头进行联合排序

1. 后端配置

  • 与单级排序的写法上没有区别

2. 前端配置

  • 与单级排序的区别:添加multiSort或者更改multiSort属性为true即可
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值