GeQin

导航

easyui datagrid 后台返回所有数据,前台分页

function pagerFilter(data) {

if (typeof data.length == 'number' && typeof data.splice == 'function') { //判断数据是否是数组
data = {
total: data.length,
rows: data
}
}
let dg = $(this);
let opts = dg.datagrid('options');
let pager = dg.datagrid('getPager');
pager.pagination({
beforePageText: “页”,
afterPageText: “页,共{pages}页”,
displayMsg: “显示{from}到{to},共{total}条记录”,
onSelectPage: function (pageNum, pageSize) {
opts.pageNumber = pageNum;
opts.pageSize = pageSize;
pager.pagination('refresh', {
pageNumber: pageNum,
pageSize: pageSize
});
dg.datagrid('loadData', data);
}
});
if (!data.originalRows) {
data.originalRows = (data.rows);
}
let start = (opts.pageNumber - 1) * parseInt(opts.pageSize);
let end = start + parseInt(opts.pageSize);
data.rows = (data.originalRows.slice(start, end));
return data;
}
$(function () {//加载数据
$('#id名').datagrid({loadFilter: pagerFilter}).datagrid('loadData', data);
});

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