$(function(){ $('#test').datagrid({ title:'分类',//表格标题 iconCls:'icon-save',//表格图标 nowrap: false,//是否只显示一行,即文本过多是否省略部分。 striped: true, url:'../../linkadminjson/sortsAction.do', //action地址 sortName: 'parentID', sortOrder: 'desc', idField:'nodeID', pageNumber:1,//当前页码 pageList:[2,4],//每一页显示的记录数,对就后台接收的rows frozenColumns:[[ ]], columns:[[ {field:'title',title:'名称',width:150}, {field:'isindex',title:'首页显示',width:60}, {field:'ishot',title:'热门',width:60}, {field:'isnew',title:'最新',width:60}, {field:'property',title:'通过审核',width:60} ]], pagination:true, //包含分页 rownumbers:true, singleSelect:true, toolbar:[{ text:'Add', iconCls:'icon-add', handler:function(){ alert('add') } },{ text:'Cut', iconCls:'icon-cut', handler:function(){ alert('cut') } },'-',{ text:'Save', iconCls:'icon-save', handler:function(){ alert('save') } }] }); });
1.jquery easyui分页方式为ajax方式分页,所以需要再后台打印json格式的数据
{ "rows":[ {"hits":0,"id":62,"imgurl":"","info":"???????\r\n","ishot":0,"isindex":0,"isnew":0,"property":1,"puttime":"2010-10-03","sid":0,"sortnum":0,"title":"??????","url":"tt"}, {"hits":0,"id":63,"imgurl":"","info":"?????\r\n","ishot":0,"isindex":1,"isnew":0,"property":1,"puttime":"2010-10-03","sid":0,"sortnum":0,"title":"?????","url":"??"} ], "total":8 }
rows: 当前显示的数据集
total:总记录数,这里记录数不是rows中的记录数,而是通过相应的hql (如:select count(*) from Sort)语句得来的记录数.
2.遇到hibernate的实体集不能转换成json格式的相关处理
如果是日期格式不能转换可以用如下方式(先去掉日期字段,看是否为日期字段不能转换):
json日期处理类
package com.dao.json; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import net.sf.json.JsonConfig; import net.sf.json.processors.JsonValueProcessor; import net.sf.json.util.CycleDetectionStrategy; public class DateJsonValueProcessor implements JsonValueProcessor { public static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd HH:mm:ss"; private DateFormat dateFormat; /** * 构造方法. * * @param datePattern 日期格式 */ public DateJsonValueProcessor(String datePattern){ try { dateFormat = new SimpleDateFormat(datePattern); } catch (Exception ex) { dateFormat = new SimpleDateFormat(DEFAULT_DATE_PATTERN); } } public Object processArrayValue(Object value, JsonConfig jsonConfig) { return process(value); } public Object processObjectValue(String key, Object value, JsonConfig jsonConfig) { return process(value); } private Object process(Object value) { return dateFormat.format((Date) value); } }
action中json格式转换代码相应的代码:
JSONObject resultObj=new JSONObject(); JsonConfig cfg = new JsonConfig(); cfg.registerJsonValueProcessor(java.util.Date.class,new DateJsonValueProcessor("yyyy-MM-dd")) ; resultObj.put("rows",JSONArray.fromObject(page.getResult(),cfg)); resultObj.put("total", page.getRowCount());//当分页建立时设置记录的总数量
3.action中需要接收并做出相应处理的几个参数说明
private int page; //当前页码,接收前台pageList:[...]中的相应的单个数据
private int rows;//每一页显示的行数