-
Notifications
You must be signed in to change notification settings - Fork 21
etmvc和extjs结合分页例子
shuzheng edited this page Aug 13, 2015
·
1 revision
分页是每个WEB应用程序必不可少的一环,数据量一大,就需要分页。分页需要前后台的配合才能完成,extjs的分页是由分页工具栏PagingToolbar完成的,而etmvc中的分页由ActiveRecord完成。
我们以显示用户资料为例子来看分页是怎么做的,建立一个分页的UserGrid,我们选择继承Ext.grid.GridPanel,这样形成的Component是可以复用的。来看看代码:
UserGrid = Ext.extend(Ext.grid.GridPanel, {
initComponent:function(){
var ds = new Ext.data.JsonStore({
url:'user/getUsers',
fields:['id','name','addr','email','remark'],
root:'users',
id:'id',
totalProperty:'total'
});
ds.load({
params:{start:0,limit:20}
});
Ext.apply(this, {
title:'用户资料管理',
store:ds,
columns:[
{header:'名称',dataIndex:'name',width:100},
{header:'地址',dataIndex:'addr',width:200},
{header:'邮箱',dataIndex:'email',width:200},
{header:'备注',dataIndex:'remark',width:300}
],
bbar:new Ext.PagingToolbar({
store:ds,
pageSize:20
})
});
UserGrid.superclass.initComponent.call(this);
}
});
我们看到,分页时的JsonStore比不分页时增加了三个属性:root, id, totalProperty。
现在来看看后台的控制器代码:
public class UserController extends ApplicationController{
public JsonView getUsers(int start, int limit) throws Exception{
long total = User.count(User.class, null, null);
List<User> users = User.findAll(User.class, null, null, "id", limit, start);
Map<String,Object> result = new HashMap<String,Object>();
result.put("total", total);
result.put("users", users);
return new JsonView(result);
}
}
我们看到,Action方法接受二个参数:start和limit,由ActiveRecord完成分页查询操作,然后返回JsonView,由etmvc将处理好的JSON串输出至客户端。
分页操作实际上并不复杂。
使用教程
- etmvc框架介绍
- Hello,World经典示例
- 关于etmvc的配置
- 理解并使用控制器
- Action方法和控制器环境
- 关于etmvc的视图
- 扩展etmvc的视图
- 利用etmvc中的模型绑定简化Action方法的编写
- ORM-ActiveRecord基础
- 利用etmvc编写用户管理小例子
- ActiveRecord中同时访问多个数据库
- ActiveRecord中的关联
- etmvc中进行上传和下载
- etmvc和extjs结合分页例子
- etmvc的过滤器基础
- ActiveRecord中集成spring
- ActiveRecord中使用事务
- etmvc中使用环绕过滤器
- ActiveRecord中的数据类型映射
- ActiveRecord中的回调方法
- etmvc框架中的插件
- etmvc框架对URL路由的支持
- etmvc中使用环绕过滤器处理异常
- etmvc中的国际化处理
- etmvc框架集成spring