Extjs4中的分页使用(前后台结合)

前台部分:

Ext.define('GS.system.role.store.RoleGridStore',{
	extend:'Ext.data.Store',
	model:'GS.system.role.model.RoleGridModel',
	id:'roleStoreId',
	pageSize:4,//分页大小
	proxy:{
		type:'ajax',
		url:'/gs_erp/roleAction!getRoleList',
	        reader: {
	            type: 'json',
	            root: 'rows',
	            totalProperty: 'total'
	        }
	},
    sorters: [{  
        property: 'id', //排序字段  
        direction: 'asc'// 默认ASC  
    }],
	autoLoad:{start: 0, limit: 4}//start是从第几条开始,limit是每页的条数
});
store.loadPage(1); //加载第一页
后台部分:

	private int limit;//每一页的条数
	private int start;//从哪一条数据开始查
	private int total;//总条数
	/**
	 * 查找所有角色
	 */
	public void getRoleList()
	{
		
		List<Role> roleList=new ArrayList<Role>();
		StringBuffer toJson=new StringBuffer();//用来放json数据
		System.out.println(start+","+limit+","+total);
		try
		{
			roleList=(List<Role>) pageServiceImpl.commonPagination(Role.class, "", start, limit);
			total=pageServiceImpl.getTotalNum(Role.class, "");
			toJson.append("{total:").append(""+total+"").append(",success:true,").append("start:")
			.append(""+start+"").append(",");
			toJson.append("rows:[");
			for(int i=0;i<roleList.size();i++)
			{
				toJson.append("{id:").append("'").append(""+roleList.get(i).getId()+"").append("'")
				.append(",name:").append("'").append(""+roleList.get(i).getName()+"")
				.append("'").append(",desc:").append("'").append(""+roleList.get(i).getDesc()+"")
				.append("'").append("}");
				if(i<roleList.size()-1)
				{
					toJson.append(",");
				}
			}
			toJson.append("]}");
		} catch (Exception e1)
		{
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		try
		{
    		response.setHeader("Cache-Control", "no-cache");
    		response.setContentType("text/json;charset=utf-8");
			response.getWriter().print(toJson);
			System.out.println(toJson);
		} catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值