参考代码
//html文件
<div id="page" class="m-pagination"></div>
//js文件
window.pagination = pagination;
//配置pagination的success事件
pagination.remote = {
getAjax: function (pagination, url, data, success, beforeSend, complate,traditional) {
$.ajax({
type:'post',
url: url,
dataType: 'json',
data: data,
cache: false,
traditional:traditional,
//contentType: 'application/Json',
beforeSend: function (XMLHttpRequest) {
if (typeof beforeSend === 'function') beforeSend.call(this, XMLHttpRequest);
},
complete: function (XMLHttpRequest, textStatue) {
if (typeof complate === 'function') complate.call(this, XMLHttpRequest, textStatue);
},
success: function (result) {
if(!result.resultInfo.success || !result.resultInfo.result.list) result.resultInfo.result = {
total: 0
};
// result.result.iTotalRecords = result.result.iTotalRecords || 0;
success.call(pagination, result);
}
})
}
}
//判断分页条是否初始化,true则销毁
if($("#page").pagination()){
$("#page").pagination('destroy');
}
/***
* 初始化分页条
* https://github.com/mricle/Mricode.Pagination
*/
$("#page").pagination({
pageIndex: 0, //当前页数
pageSize: 5, //每页条数
debug: false,
showInfo: true,
showJump: true,
firstBtnText: "首页",
lastBtnText: "尾页",
pageBtnCount: 9,
pageElementSort: ['$page', '$jump', '$info'],
infoFormat: '共{totalPage}页{total}条',
jumpBtnText: "确定",
remote: {
url: ContextPath + '/manage/approve/getApprovedPageData',
success: function (d) {
/**
**ajax成功执行
**/
},
totalName: 'resultInfo.result.total', //总条数字段,当前为'd.result.total'
pageParams: function(data){ //配置ajax参数
return $.extend({},{
pageNum: data.pageIndex + 1, //当前页,默认0开始
pageSize: data.pageSize //每页条数
},{});
}
}
});