Extjs4中的分页应用结合前后台
人气:0
前台部分:
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();
}
}
复制代码 代码如下:
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();
}
}
加载全部内容