其他分享
首页 > 其他分享> > layui所有数据排序

layui所有数据排序

作者:互联网

去掉自带排序 [autoSort: false]

table.render({
     elem: '#test'
   , url: '/DataShow/WarnEventList' //数据接口
   , where: { 
   bm: document.getElementById("deptFj").value,
    bdz: $('#subsFj').val()
    } //如果无需传递额外参数,可不加该参数
   , width: '100%'
   , height: h
   , autoSort: false //去掉自排序
   , id: 'testReload'
   , cols: [[
     { type: 'checkbox',  fixed: 'left' }
      //{ field: 'zizeng', width: 49, title: '序号', fixed: 'left', type: 'numbers' }
     //, { field: 'ID', width: w * 0.1, title: 'ID', fixed: 'left' }
     , {
         field: 'LINE_NAME', width: w * 0.1, title: '线路' 
     },
     , {
         field: 'FILETYPE', width: w * 0.1, title: '类型' , templet:
         function (d) {
             if (d.FILETYPE == "0") {
                 return "<span style='color:red;'>故障录波</span>";
             } else if (d.FILETYPE == "1") {
                 return "<span style='color:blue;'>召唤录波</span>";
             } else{
                 return "<span>其他</span>";
             }
         }
     }
     , { field: 'INSERTTIME', width: w * 0.2, title: '数据时间', sort: true }
     , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 170 }
   ]]
   , page: true   //开启分页
   , limit: 20      //每页显示数
   , limits: [10, 20, 30, 40, 50, 60, 70, 80, 90]
   , async: false  //false同步, true异步
     //, text: {
     //    none: '暂无相关数据' //默认:无数据。注:该属性为 layui 2.2.5 开始新增
     //}
 });

定义全局变量

var orderby = ""; var ordertype = "desc";
function getpx(orderby, ordertype) { }

重写排序,后台请求传排序字段

// 自定义排序
table.on('sort(test)', function (obj) {
    table.reload('testReload', {
        where: { //请求参数(注意:这里面的参数可任意定义,并非下面固定的格式)
            bm: document.getElementById("deptFj").value,
            bdz: $('#subsFj').val(),
            field: obj.field, //排序字段
            order: obj.type //排序方式
        },
    });
    if (obj.field == 'FILESIZE') {
        orderby = "FILESIZE";
    } else if (obj.field == 'STATE') {
        orderby = "STATE";
    } else if (obj.field == 'INSERTTIME') {
        orderby = "INSERTTIME";
    }
    if (obj.type == 'desc') {
        ordertype = 'desc';
    } else if (obj.type == 'asc') {
        ordertype = 'asc';
    }
    getpx(orderby, ordertype);
});

标签:orderby,obj,field,layui,所有,width,title,排序
来源: https://blog.csdn.net/weixin_43151418/article/details/115248117