Struts2 + easyui的DataGrid 分页
2014-03-24 13:05
309 查看
jsp页面
js代码:
$(function() {
$('#ff').hide();
$('#tt').datagrid({
title : '信息显示',
iconCls : 'icon-save',
width : 'auto',
height : 'auto',
pageSize:10,
pageList : [ 5, 10, 15 ],
nowrap : true,
striped : true,
collapsible : true,
url : 'pecc/peccList.action',
loadMsg : '数据装载中......',
onLoadError : function() {
alert('数据加载失败!');
},
sortName : 'code',
sortOrder : 'desc',
remoteSort : false,
frozenColumns : [ [ {
field : 'ck',
checkbox : true
} ] ],
columns : [ [ {
title : '车牌号',
field : 'carNumber',
width : '100',
rowspan : 2,
align : 'center'
}, {
title : '车主',
field : 'carPer',
width : '100',
rowspan : 2,
align : 'center'
}, {
title : '违章时间',
field : 'pTime',
width : '80',
rowspan : 2,
align : 'center'
}, {
title : '违章地点',
field : 'pPlace',
width : '220',
rowspan : 2,
align : 'center'
}, {
title : '违章原因',
field : 'pCase',
width : '220',
rowspan : 2,
align : 'center'
}, {
title : '来源',
field : 'pOrg',
width : '120',
rowspan : 2,
align : 'center'
}, {
title : '交警大队',
field : 'pPer',
width : '300',
rowspan : 2,
align : 'center'
} ] ],
pagination : true,
rownumbers : true,
toolbar : [ {
text : '全部',
iconCls : 'icon-ok',
handler : function() {
$('#tt').datagrid({
url : 'pecc/peccList.action'
});
}
}, '-', {
text : '添加',
iconCls : 'icon-add',
handler : function() {
openAdd();
$('#ff').show();
$('#ff').form('clear');
$('#ff').appendTo('#aa');
}
}, '-', {
text : '修改',
iconCls : 'icon-edit',
handler : getSelect
}, '-', {
text : '删除',
iconCls : 'icon-remove',
handler : del
}, '-', {
text : '查询',
iconCls : 'icon-search',
handler : function() {
$('#query').window('open');
}
} ]
});
displayMsg();
});
function displayMsg() {
$('#tt').datagrid('getPager').pagination({
displayMsg : '当前显示从{from}到{to}共{total}记录'
});
}
Action 代码:
@Controller
@ParentPackage("mydefault")
@Namespace("")
public class Pecc extends ActionSupport {
private static final long serialVersionUID = 1L;
@Resource
PerinfoService perinfoService;
@Resource
PeccancyService peccancyService;
@Action("/pecc")
public String peccList() {
try {
HttpServletRequest re = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
JSONArray jsonArray = new JSONArray();
JSONObject jsonobj = new JSONObject();
Map map = new HashMap();
long all = perinfoService.getCount(map);
String page = re.getParameter("page");
String rows = re.getParameter("rows");
// 当前页
int intPage = Integer.parseInt((page == null || page == "0") ? "1" : page);
// 每页显示条数
int number = Integer.parseInt((rows == null || rows == "0") ? "10" : rows);
// 每页的开始记录 第一页为1 第二页为number +1
int start = (intPage - 1) * number;
map.put("page", start);
map.put("pageCount", number);
List list = peccancyService.getList(map);
for (Peccancy con : list) {
jsonobj.put("id", con.getId());
jsonobj.put("carNumber", con.getCarNumber());
jsonobj.put("carPer", con.getCarPer());
jsonobj.put("pTime", sdf.format(con.getPTime()));
jsonobj.put("pPlace", con.getPPlace());
jsonobj.put("pCase", con.getPCase());
jsonobj.put("pOrg", con.getPOrg());
jsonobj.put("pPer", con.getPPer());
jsonArray.add(jsonobj);
}
Map json = new HashMap();
json.put("total", all);// total键 存放总记录数,必须的
json.put("rows", jsonArray);// rows键 存放每页记录 list
jsonobj = JSONObject.fromObject(json);// 格式化result一定要是JSONObject
out.print(jsonobj);
out.flush();
out.close();
} catch (IOException e) {
System.out.println(e);
}
return null;
}
Struts.xml 配置:
<</span>package name="mydefault" extends="struts-default">
<</span>global-results>
<</span>result name="exception">/index.jsp</</span>result>
</</span>global-results>
<</span>global-exception-mappings>
<</span>exception-mapping exception="java.lang.Exception"
result="exception" />
</</span>global-exception-mappings>
</</span>package>
js代码:
$(function() {
$('#ff').hide();
$('#tt').datagrid({
title : '信息显示',
iconCls : 'icon-save',
width : 'auto',
height : 'auto',
pageSize:10,
pageList : [ 5, 10, 15 ],
nowrap : true,
striped : true,
collapsible : true,
url : 'pecc/peccList.action',
loadMsg : '数据装载中......',
onLoadError : function() {
alert('数据加载失败!');
},
sortName : 'code',
sortOrder : 'desc',
remoteSort : false,
frozenColumns : [ [ {
field : 'ck',
checkbox : true
} ] ],
columns : [ [ {
title : '车牌号',
field : 'carNumber',
width : '100',
rowspan : 2,
align : 'center'
}, {
title : '车主',
field : 'carPer',
width : '100',
rowspan : 2,
align : 'center'
}, {
title : '违章时间',
field : 'pTime',
width : '80',
rowspan : 2,
align : 'center'
}, {
title : '违章地点',
field : 'pPlace',
width : '220',
rowspan : 2,
align : 'center'
}, {
title : '违章原因',
field : 'pCase',
width : '220',
rowspan : 2,
align : 'center'
}, {
title : '来源',
field : 'pOrg',
width : '120',
rowspan : 2,
align : 'center'
}, {
title : '交警大队',
field : 'pPer',
width : '300',
rowspan : 2,
align : 'center'
} ] ],
pagination : true,
rownumbers : true,
toolbar : [ {
text : '全部',
iconCls : 'icon-ok',
handler : function() {
$('#tt').datagrid({
url : 'pecc/peccList.action'
});
}
}, '-', {
text : '添加',
iconCls : 'icon-add',
handler : function() {
openAdd();
$('#ff').show();
$('#ff').form('clear');
$('#ff').appendTo('#aa');
}
}, '-', {
text : '修改',
iconCls : 'icon-edit',
handler : getSelect
}, '-', {
text : '删除',
iconCls : 'icon-remove',
handler : del
}, '-', {
text : '查询',
iconCls : 'icon-search',
handler : function() {
$('#query').window('open');
}
} ]
});
displayMsg();
});
function displayMsg() {
$('#tt').datagrid('getPager').pagination({
displayMsg : '当前显示从{from}到{to}共{total}记录'
});
}
Action 代码:
@Controller
@ParentPackage("mydefault")
@Namespace("")
public class Pecc extends ActionSupport {
private static final long serialVersionUID = 1L;
@Resource
PerinfoService perinfoService;
@Resource
PeccancyService peccancyService;
@Action("/pecc")
public String peccList() {
try {
HttpServletRequest re = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
JSONArray jsonArray = new JSONArray();
JSONObject jsonobj = new JSONObject();
Map map = new HashMap();
long all = perinfoService.getCount(map);
String page = re.getParameter("page");
String rows = re.getParameter("rows");
// 当前页
int intPage = Integer.parseInt((page == null || page == "0") ? "1" : page);
// 每页显示条数
int number = Integer.parseInt((rows == null || rows == "0") ? "10" : rows);
// 每页的开始记录 第一页为1 第二页为number +1
int start = (intPage - 1) * number;
map.put("page", start);
map.put("pageCount", number);
List list = peccancyService.getList(map);
for (Peccancy con : list) {
jsonobj.put("id", con.getId());
jsonobj.put("carNumber", con.getCarNumber());
jsonobj.put("carPer", con.getCarPer());
jsonobj.put("pTime", sdf.format(con.getPTime()));
jsonobj.put("pPlace", con.getPPlace());
jsonobj.put("pCase", con.getPCase());
jsonobj.put("pOrg", con.getPOrg());
jsonobj.put("pPer", con.getPPer());
jsonArray.add(jsonobj);
}
Map json = new HashMap();
json.put("total", all);// total键 存放总记录数,必须的
json.put("rows", jsonArray);// rows键 存放每页记录 list
jsonobj = JSONObject.fromObject(json);// 格式化result一定要是JSONObject
out.print(jsonobj);
out.flush();
out.close();
} catch (IOException e) {
System.out.println(e);
}
return null;
}
Struts.xml 配置:
<</span>package name="mydefault" extends="struts-default">
<</span>global-results>
<</span>result name="exception">/index.jsp</</span>result>
</</span>global-results>
<</span>global-exception-mappings>
<</span>exception-mapping exception="java.lang.Exception"
result="exception" />
</</span>global-exception-mappings>
</</span>package>
相关文章推荐
- Struts2 + easyui的DataGrid 分页
- EasyUI datagrid URL请求参数
- Struts2 + easyui的DataGrid 分页
- Struts2 + easyui的DataGrid 分页
- easyui的datagrid整合struts2,以及Ajax,实现局部刷新功能,并设置分页的实现---------投票案例
- Struts2获取easyUI datagrid 分页参数page和rows
- EasyUI Datagrid 分页
- Asp.Net MVC EasyUI DataGrid查询分页
- java递归组装easyui combotree
- easyui datagrid 的分页刷新按钮
- easyui datagrid 分页
- EasyUI 之 DataGrid分页组件中文显示的两种方法(语言的切换)
- easyui datagrid client搜索、分页、排序
- Struts2整合EasyUI DataGrid传递JSON数据【要点及常见错误】
- easyui datagrid 生成动态列后 实现分页
- Spring MVC PK Struts2
- oracle 分页视频
- easyUI DataGrid基础
- (easyui datagrid+mvc+json)之asp.net分页查询
- springmvc+easyUI的DataGrid分页功能