EasyUidatagrid实现表格分页
1.⾸先引⼊ easyui的 css 和 js ⽂件
2.前台需要写的js
复制代码代码如下:
//源数据
function Async(action,args,callback){
$.ajax({
  url: action ,
  type:"POST",
  dataType:"json",
  timeout: 10000,
  data: args,
  success: function(data){
    if(callback){
  callback(data);
  }
  }
});
}
//绑定数据并设置分页
function BingData(pid,args,action,callback){
Async(action,args,function(data){
if(data!=null&&data.list!=null){
var _dataCount=data.size;//总条数
var _data=data.list;//数据
if(callback){
callback(_data);
}
$(pid).datagrid('loadData', _data);
$(pid).datagrid('getPager').pagination({
beforePageText: '第',
afterPageText: '页共 {pages} 页',
displayMsg: '当前显⽰ {from} - {to} 条记录共 {total} 条记录',
pageSize: args.pageSize,
total: _dataCount,
pageNumber: args.pageIndex,
pageList:args.pageList,
onSelectPage: function (pageNumber, pageSize) {
args.pageIndex = pageNumber;
args.pageSize = pageSize;
BingData(pid, args, action,null);
},
onRefresh: function (pageNumber, pageSize) {
args.pageIndex = pageNumber;
args.pageSize = pageSize;
BingData(pid, args, action,null);
}
});
}
});
}
//表单序列化为对象
$.fn.serializeObject = function(){
var obj = {};
$.each( this.serializeArray(), function(i,o){
var n = o.name, v = o.value;
obj[n] = obj[n] === undefined ? v
: $.isArray( obj[n] ) ? obj[n].concat( v )
: [ obj[n], v ];
});
return JSON.stringify(obj);
};
//宽度
function fixWidth(percent){
return document.body.clientWidth * percent ;
}
/
/结束编辑
function endEdit(vid){
vid = "#"+vid;
var tb=$(vid);
var rows = tb.datagrid('getRows');
for ( var i = 0; i < rows.length; i++) {
tb.datagrid('endEdit', i);
}
}
function GetData(obj){
var url = contextPath+'/fundRetreatVoucher/fundBatchRetreatVoucherQuery.htm';//action路径
var args={};
args.pageIndex=1;//页索引
args.pageSize=10;//页容量
if(obj!=null){  //表单序列化的对象
args.obj=obj;
}
BingData("#tab",args,url,null);
}
function getTab(){
GetData();
var tb=$('#tab');
tb.datagrid({
title : '资⾦退回批次查询结果',
striped : true,
fitColumns: true, //⾃适应列的⼤⼩
rownumbers: true,
nowrap : true,//设置为true,当数据长度超出列宽时将会⾃动截取
striped : true,
width:fixWidth(0.99),
height:'430',
singleSelect:true,
loadMsg : '数据装载中......',
columns:[[
  {field:'interfaceInfoCode',title:'资⾦通道编码',width:fixWidth(0.3),align: "center"},
{field:'retreatBatchCode',title:'资⾦退回批次号',width:fixWidth(0.2),editor:'text' ,align: "center"},          {field:'total',title:'总笔数',width:fixWidth(0.1),align:'right',editor:'text' ,align: "center"},
    {field:'totalMoney',title:'总⾦额',width:fixWidth(0.1),align:'right',editor:'text' ,align: "center"},          {field:'def2',title:'操作',width:fixWidth(0.3),editor:'text',align:'right' ,align: "center",
    formatter:function(value,row,index){
    var vcode =atBatchCode;
    var e = '<a href="#" onclick="toDetail('+index+')">详情</a> | ';
    var d = '<a href="#" onclick="auditBatch('+index+',0)">审核通过</a> | ';
    var f = '<a href="#" onclick="auditBatch('+index+',1)">审核拒绝</a> ';
    return e+d+f;
    }}
  ]],
  onLoadSuccess:function(data){
  if (al == 0) {
  }
  },
  pagination: true,
  pageIndex:1,//页索引
  pageSize:10,//页容量
  pageList: [10,15,20]
jquery实现ajax
  })
}
2 后台
复制代码代码如下:
int currentPage = Parameter("pageIndex") == null ? 1 : Integer.Parameter("pageIndex")); // 每页⾏数
int showCount = Parameter("pageSize") == null ? 10 : Integer.Parameter("pageSize")); // 分页实体
String obj = Parameter("obj");
if (Blank(obj)) {
fundRetreatVoucher = Object(obj, FundRetreatVoucherParam.class); //表单序列化json对象转为实体
}
out = Writer();
List<FundRetreatVoucher> frvs = fundRetreatVoucherService.findAllFundRetreatVoucher(page, fundRetreatVoucher); int total = fundRetreatVoucherService.findAllFundRetreatVoucher(getTotal(), fundRetreatVoucher).size();//数据⼤⼩JSONObject json = new JSONObject();
json.put("list", frvs);//数据,这⾥的put的key ,⼀定要为list,如果改了需要把 BingData中的数据改⼀下
json.put("size", total);
out.print(json);

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。