GeQin

导航

easyui datagrid 后台分页,前端如何处理


module.exports = {
queryMethod(){
let params = checkQueryParams.call(this);
if (!params) {
return;
}
//ajax请求,$UPost,$UConfApi是我在项目中封装好的方法,其实就是调取后台接口,$UPost是一个promise对象,所以可以用then()方法,params是传给后台的参数
return $UPost($UConfApi('H_Log_Operate'), params).then(result => { //es6箭头函数的写法
if (!result || result.rows < 1) {
return alert(“无查询结构!”);
}
let pager = $('#grid').datagrid('getPager');
pager.pagination('refresh', {
total:result.results
});
pager.pagination({
onSelectPage: function (pageNum, pageSize) {
let start = parseInt(pageNum-1)*parseInt(pageSize);
let limit = parseInt(pageSize);
//再次调用接口,取到新数据
$UPost($UConfApi('H_Log_Operate'), {start:start,limit:limit}).then(result => {
let data = result.rows;
$('#grid').datagrid('loadData',data);
pager.pagination('refresh', {
total:result.results,
pageNumber: pageNum,
pageSize: pageSize
});
})

}
});
})

},
}

//获取参数
function checkQueryParams() {

let {
LangCommon: lang,
LangUser
} = $ULanguage();
let {
starttime,
endtime,
accountid,
start = 0,
limit
} = this;
accountid = $('#accountid').textbox('getText');
starttime = $("#range-time-start").val();
endtime = $("#range-time-end").val();
let shortName = $("#shortname").combobox('getText');
if(!shortName){
return $UToolAlert(LangUser.shortname_null);
}
if (!accountid) {
return $UToolAlert(lang.exist);
}
if (!starttime || !endtime) {
return $UToolAlert(lang.dateHint)
}
//分页相关内容start
    let opts = $('#grid').datagrid('options');
let pager = $('#grid').datagrid('getPager');
    pager.pagination({
onSelectPage: function (pageNum, pageSize) {
opts.pageNumber = pageNum;
opts.pageSize = pageSize;
}
});
start = parseInt(opts.pageNumber-1)*parseInt(opts.pageSize);
limit = parseInt(opts.pageSize);
//分页相关内容end
    return {
starttime,
endtime,
accountid,
start,
limit
};
}

posted on 2017-07-25 10:42  GeQin  阅读(1525)  评论(0编辑  收藏  举报