easyui datagrid sort 表头 排序

来源:互联网 发布:mac vscode 取消撤销 编辑:程序博客网 时间:2024/06/05 23:58
easyui datagrid sort 表头 排序

转自:http://blog.csdn.net/changjiadashaoye/article/details/41849497

      datagrid的点击列表头刷新,分为两种,一种是页面刷新,不涉及后台服务器数据,不会从新查询数据库,只会刷新当前页数据;

一种是服务器级刷新,会重新加载全部数据。

如果不需要自定义排序,可以直接使用

    remoteSort:false,  
    sortName:'',  
    sortOrder:'asc',

一些特殊排序,或者特殊字段可以使用以下的方法

1、将服务器对数据项排序设置为false(必须)

2、设置field的排序属性为true,sorter的function内容自己写,如果该字段为数字或者字符串,可以用以下方法:

 如果是时间类型,可使用以下方法:

复制代码
{field:'actual_start_time',title:'实际开始时间',width:100,         formatter:function(value,row,index){              if(value != null && '' != value)                return new Date(value).format("yyyy/MM/dd");          },         sortable:true,         sorter:function(a,b){            a = a.split('/');            b = b.split('/');            if (a[0] == b[0]){                if (a[1] == b[1]){                    return (a[2]>b[2]?1:-1);                } else {                    return (a[1]>b[1]?1:-1);                }            } else {                return (a[0]>b[0]?1:-1);            }    }   },
复制代码

第二种,服务器刷新,只能单列排序

1、将服务器对数据项排序设置为true,对要排序的列增加属性

2、后台分页查询方法,需要接收两个string类型的参数,sort以及order 参数名是固定的

如果有封装分页方法,则自己的查询sql不需要这两个参数,如果没有封装,则需要根据这两个参数排序

以下是封装的底层分页方法,sqlPage.append(" ORDER BY "+sort+" "+order);

需要在服务器接收两个参数:

String sort = request.getParameter("sort");
String order = request.getParameter("order");

原创粉丝点击