easyui datagrid 前台分页代码
//分页
function pagerFilter(data) {
if (typeof data.length == 'number' && typeof data.splice == 'function') { // is array
data = {
total: data.length,
rows: data
}
}
var dg = $(this);
var opts = dg.datagrid('options');
var pager = dg.datagrid('getPager');
pager.pagination({
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);
}
var start = (opts.pageNumber - 1) * parseInt(opts.pageSize);
var end = start + parseInt(opts.pageSize);
data.rows = (data.originalRows.slice(start, end));
return data;
}
$('#List').datagrid({
data: info.grid,
width: $(window).width() - 282,
rownumbers: true,
fitColumns: true,
fit: true,//自适应
columns: info.columns,
sortName: 'Id',
sortOrder: 'Asc',
idField: 'Id',
methord: 'post',
pagination: true,
pageSize: 20,
pageList: [10, 20, 50, 100],
loadFilter: pagerFilter
});