81,092
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="false" />
<constant name="struts.url.includeParams" value="none" />
<constant name="struts.ui.theme" value="simple" />
<package name="meswork" extends="json-default">
<action name="getDes" class="com.bhmc.action.DevicesManageAction" method="getDes">
<result name="success" type="json">
<param name="includeProperties">
^gridModel/[/d+/]/./w+,
rows, page, total, record
</param>
<param name="noCache">true</param>
<param name="ignoreHierarchy">false</param>
</result>
</action>
......
package com.bhmc.action;
import java.util.Collections;
import java.util.List;
import org.apache.struts2.json.annotations.JSON;
import com.opensymphony.xwork2.ActionSupport;
public abstract class BaseAction<T> extends ActionSupport{
private static final long serialVersionUID = 1L;
private List<T> gridModel = Collections.emptyList();
private Integer rows = 0;
private Integer page = 0;
private Integer total = 0;
private Integer record = 0;
private String sord;
private String sidx;
private String search;
public abstract int getResultSize();
public abstract List<T> listResults(int from, int length);
public String refreshGridModel() {
try {
List<T> results = Collections.emptyList();
record = this.getResultSize();
int from = rows * (page - 1);
int length = rows;
results = this.listResults(from, length);
this.setGridModel(results);
total = (int) Math.ceil((double) record / (double) rows);
return SUCCESS;
} catch (Exception e) {
e.printStackTrace();
this.addActionError(e.getMessage());
return ERROR;
}
}
@JSON(serialize=true)
public List<T> getGridModel() {
return gridModel;
}
public void setGridModel(List<T> gridModel) {
this.gridModel = gridModel;
}
public Integer getRows() {
return rows;
}
public void setRows(Integer rows) {
this.rows = rows;
}
public Integer getPage() {
return page;
}
public void setPage(Integer page) {
this.page = page;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public Integer getRecord() {
return record;
}
public void setRecord(Integer record) {
this.record = record;
}
public String getSord() {
return sord;
}
public void setSord(String sord) {
this.sord = sord;
}
public String getSidx() {
return sidx;
}
public void setSidx(String sidx) {
this.sidx = sidx;
}
public String getSearch() {
return search;
}
public void setSearch(String search) {
this.search = search;
}
}
package com.bhmc.action;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.apache.struts2.ServletActionContext;
import com.bhmc.bean.Devices;
import com.bhmc.bean.User;
import com.bhmc.service.ManageServiceIf;
public class DevicesManageAction extends BaseAction<Devices> {
/**
*
*/
private static final long serialVersionUID = 1L;
private ManageServiceIf devicesManageService;
public void setDevicesManageService(ManageServiceIf devicesManageService){
this.devicesManageService = devicesManageService;
}
public String getDes(){
return this.refreshGridModel();
}
@SuppressWarnings("unchecked")
public List<Devices> listResults(int from, int length) {
List<Devices> results = Collections.emptyList();
results = (List<Devices>) devicesManageService.queryResults(from, length);
return results;
}
@Override
public int getResultSize() {
return Integer.valueOf(devicesManageService.count());
}
}
$(function(){
// 配置jqGrid组件
$("#gridTable").jqGrid({
url: "getDes.action",
datatype: "json",
mtype: "GET",
height: 350,
autowidth: true,
colModel: [
{name:"deviceid",index:"deviceid",label:"deviceid",width:40},
{name:"type",index:"type",label:"type",width:80,sortable:false},
{name:"brand",index:"brand",label:"brand",width:80,sortable:false},
{name:"model",index:"model",label:"model",width:160,sortable:false},
{name:"function",index:"function",label:"function",width:120,sortable:false} ,
{name:"shop",index:"shop",label:"shop",width:80,sortable:false},
{name:"position",index:"position",label:"position",width:80,sortable:false},
{name:"state",index:"state",label:"state",width:80,sortable:false},
{name:"ip",index:"ip",label:"ip",width:80,sortable:false},
{name:"account",index:"account",label:"account",width:80,sortable:false},
{name:"password",index:"password",label:"password",width:80,sortable:false},
{name:"os",index:"os",label:"os",width:80,sortable:false},
{name:"computername",index:"computername",label:"computername",width:80,sortable:false},
{name:"serialno",index:"serialno",label:"serialno",width:80,sortable:false},
{name:"assetno",index:"assetno",label:"assetno",width:80,sortable:false},
{name:"buyer",index:"buyer",label:"buyer",width:80,sortable:false},
{name:"buydate",index:"buydate",label:"buydate",width:80,sortable:false},
{name:"project",index:"project",label:"project",width:80,sortable:false},
{name:"enviroment",index:"enviroment",label:"enviroment",width:80,sortable:false},
{name:"software",index:"software",label:"software",width:80,sortable:false},
{name:"price",index:"price",label:"price",width:80,sortable:false},
{name:"comment",index:"comment",label:"comment",width:80,sortable:false},
],
viewrecords: true,
rowNum: 15,
rowList: [15,50,100],
prmNames: {search: "search"}, //(1)
jsonReader: {
root:"gridModel", // (2)
records: "record", // (3)
repeatitems : false // (4)
},
pager: "#gridPager",
caption: "DeviceList/////////////",
hidegrid: false
});
});
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN">
<head>
<title>jqGrid01</title>
<link rel="stylesheet" type="text/css" media="screen" href="css/jquery-ui.min.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<script type="text/javascript" src="js/jquery-1.11.0.min.js" ></script>
<script src="js/jquery-ui.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-cn.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.js" type="text/javascript"></script>
<script src="js/jqGrid01.js" type="text/javascript"></script>
</head>
<body>
<h2>
jqGrid测试 01
</h2>
<div>
<table id="gridTable">
</table>
<div id="gridPager"></div>
</div>
</body>
</html>