以下示例使用JQuery Easy UI、Spring MVC:
首先定义一个DataGrid:
$('#tt').datagrid({
fit:true,
pageNumber:1,
pageList:[10,20,50],
url:'${pageContext.request.contextPath}/branch_office/list/json.htm',
nowrap: false,
striped: true,
collapsible:true,
remoteSort: false,
columns:[[
{title:'名称',field:'name',width:300,sortable:true,sorter:function(a,b){ return (a>b?1:-1);}},
{title:'创建时间',field:'createTime',width:150,sortable:true,sorter:function(a,b){ return (a>b?1:-1);}},
{title:'修改时间',field:'modifyTime',width:150,sortable:true,sorter:function(a,b){ return (a>b?1:-1);}}
]],
pagination:true,
singleSelect:true,
rownumbers:true
});
在Spring MVC 的Controller 中的方法,返回Json格式的数据:
@RequestMapping(value = "/branch_office/list/json", method = RequestMethod.POST)
public
@ResponseBody
Map<String, Object> getJson(int page, int rows, Map<String, Object> map) {
//DataGrid 会向 请求Json 的地址以POST方法发送2个参数:page(当前页码)和rows(每页显示记录数)
//获取分页数据
List<BranchOfficeViewObject> branchOfficeVOList = iBranchOfficeService.showList(page, rows);
//获取总记录数
int totalRows = iBranchOfficeService.getTotalRows();
map.put("total", totalRows);
map.put("rows", branchOfficeVOList);
//返回指定格式的Map,Jackson会把Map转换未Json
return map;
}