JQGrid 예 주요 부분

4470 단어 jqGrid
1. 프론트 데스크 페이지:
다음 두 개의 div를 Body 태그에 놓으십시오. table은 데이터의 용기이고 div는 도구막대입니다
<DIV class="ui-layout-center">
	<table id="gridList"></table>
	<div id="pagerBar"></div>
</DIV>

//js 부분
//     
var jqgrid_colNames=['nodeCode','nodeName', 'domain'];
//     
var jqgrid_colModel = [	
			{
				name:'nodeCode',
				index:'nodeCode', 
				width:80,
				align:"center",
				editable:true
			},{
				name:'nodeName',
				index:'nodeName',
				width:80,
				editable:true,
				editoptions:{size:10},
				required:true
			},{
				name:'domain',
				index:'domain', 
				width:90,
				editable:true,
				editoptions:{size:25},
				required:true
			}
		];

//   jqgrid,  jquery ready 
function jqgridInit () {
	jQuery("#gridList").jqGrid({
		url:'/ibrms/brm/dirMgt_testJQGrid.action',
		datatype: "json",
		colNames:jqgrid_colNames,
		colModel:jqgrid_colModel,
		rowNum:10,
		rowList:[10,20,30],
		pager: '#pagerBar',
		sortname: 'nodeCode',
		viewrecords: true,
		sortorder: "desc",
		caption:"     ",
		height:"400",
		autowidth:true,
		toolbar: [true,'top'],
		editurl:"someurl.php",
		jsonReader:{ 
			root:"dataRows",  
			page: "currentPage",
			total: "totalPages", 
			records: "records", 
			repeatitems: false
		}
	}).navGrid('#pagerBar',{ edit:true, add:true, del:true});

2. 백그라운드:
//     json    
//    , jqgrid           。
public class JQGridResponse {
	private int totalPages; //   
	private int currentPage; //    
	private int records; //    
	private JSONArray dataRows;//JSONArray    
	
	public JQGridResponse() {
		this.totalPages = 0;
		this.currentPage = 0;
		this.records = 0;
		this.dataRows = new JSONArray();
	}
	//    get/set  
}

Action:
public void testJQGrid(){
	JQGridResponse grid= new JQGridResponse();
        //    
	BrmNode brmNode1 = new BrmNode();
	brmNode1.setNodeCode("001");
	brmNode1.setNodeName("node1");
	brmNode1.setDomain("ibrms");

	BrmNode brmNode2 = new BrmNode();
	brmNode2.setNodeCode("002");
	brmNode2.setNodeName("node2");
	brmNode2.setDomain("ibrms");

	BrmNode brmNode3 = new BrmNode();
	brmNode3.setNodeCode("003");
	brmNode3.setNodeName("node3");
	brmNode3.setDomain("ibrms");
        //     list
	List list = new ArrayList();
	list.add(brmNode1);
	list.add(brmNode2);
	list.add(brmNode3);
        //       
	grid.setCurrentPage(1);
	grid.setTotalPages(1);
	grid.setRecords(3);
        // list   JSONArray  
	grid.setDataRows(JSONArray.fromObject(list));

	ResponseWriteUtil.print2JsonObj(response, grid);
	}

ResponseWriteUtil.print2JsonObj 메서드:
public static void print2JsonObj(HttpServletResponse response,Object object) {
		PrintWriter out = null;
		try {
			out = response.getWriter();
			JsonConfig jsonConfig = new JsonConfig();
			jsonConfig.registerJsonValueProcessor(Timestamp.class,new JsonValueProcessorTimestamp());
			JSONObject	jsonObject = JSONObject.fromObject(object, jsonConfig);
			log.debug(jsonObject.toString());
			out.print(jsonObject);
		} catch (IOException e) {
			log.debug(e);
		} finally {
			out.close();
		}
	}

Struts2 구성:
<package name="com.test" namespace="/brm" extends="json-default">
     <action name="dirMgt_*" class="com.test.action.DirMgtAction" method="{1}">
		<result name="success"></result>
     </action>
</package>

좋은 웹페이지 즐겨찾기