- 在 datagrid中加上loadFilter: pagerFilter,复制pagerFilter方法
$('#table').datagrid({
title: '商品详情',
url: '#',
fitColumns: true,
pageSize: 10,
pageList: [10, 20, 30],
singleSelect: false,
pagination: true,
width: "100%",
height: "auto",
striped: true,
nowrap: true,
rownumbers: true,
loadFilter: pagerFilter,
collapsible: true,
remoteSort: false,
columns: [[
{field: '#', title: '#', width: 30, checkbox: true},
{field: 'id', title: '序号', width: 100, align: 'center'},
{field: 'picture', title: '图片', width: 100, align: 'center'},
{field: 'details', title: '详情', width: 120, align: 'center'},
{field: 'amount', title: '金额', width: 120, align: 'center'}
]]
});
- 分页方法
function pagerFilter(data) {
if (typeof data.length == 'number' && typeof data.splice == 'function') {
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;
}