1、选择字段的排序时触发 记录了 排序需要的字段和排序类型
table.on('sort(laytable)', function (obj) { let type = obj.type, field = obj.field; $(":input[name='field']").val(field); $(":input[name='order']").val(type); initSort = obj; tabInit(0); }); 2、表格重载中的配置 function reloadGoods(special) { var column = []; if (special == 0) { column = '{{$fields}}'; } else { column = '{{$fieldsSpecial}}'; } column = JSON.parse(html_decode(column)); var url = '{{route('goods')}}/'; var stroage_Id = "goods_curr_"+special; var rowCount = localStorage.getItem('goods_limits') ? localStorage.getItem('goods_limits') : 20; var d = getWhereArr(); table.render({ elem:'#myTable', url: url + special, where:d, limit:rowCount, autoSort: false,//是否前端排序 initSort:initSort,//排序状态 page:{ curr:localStorage.getItem(stroage_Id) ? localStorage.getItem(stroage_Id) : 1, }, parseData:function (res) { return { 'code' : 0, 'count' : res.total, 'data' : res.data, } }, cols:column, done: function (res, curr, count) { //console.log(res) var indexLimit = $(".layui-laypage-limits").find("option:selected").val(); localStorage.setItem('goods_limits',indexLimit);//存储每页显示 localStorage.setItem(stroage_Id,curr);//存储页码 } }); } function getWhereArr() { var d = {}; var t = $('#formSearch [name]').serializeArray(); $.each(t, function() { d[this.name] = this.value; }); return d; } 3、后台进行排序条件查询