layui 2.2.45的table扩展server端排序

分享 未结
1 758
Merlin
Merlin 2017-12-20
悬赏:20飞吻
//扩展server端排序
if(that.config.sidePagination && typeof that.config.sidePagination === 'object') {
var _where = options.where || {};
if(field != _where[options.sidePagination.sortKey] || (type||"") != (_where[options.sidePagination.sortExtKey]||"")) {
if(type === 'asc'){ //升序
_where[options.sidePagination.sortKey] = field;
_where[options.sidePagination.sortExtKey] = type;
} else if(type === 'desc'){ //降序
_where[options.sidePagination.sortKey] = field;
_where[options.sidePagination.sortExtKey] = type;
} else { //清除排序
delete _where[options.sidePagination.sortExtKey];
}
that.reload();

if(formEvent){
layui.event.call(th, MOD_NAME, 'sort('+ filter +')', {
field: field
,type: type
});
}
} else {
res[options.response.dataName] = data;
that.renderData(res, that.page, that.count, true);
}
// client端排序
} else {
if(type === 'asc'){ //升序
thisData = layui.sort(data, field);
} else if(type === 'desc'){ //降序
thisData = layui.sort(data, field, true);
} else { //清除排序
thisData = layui.sort(data, table.config.indexName);
delete that.sortKey;
}

res[options.response.dataName] = thisData;
that.renderData(res, that.page, that.count, true);
if(formEvent){
layui.event.call(th, MOD_NAME, 'sort('+ filter +')', {
field: field
,type: type
});
}
}
回帖
本帖已设置禁止回复