spring + jqgrid + json 예제

SPRING 2016. 11. 8. 17:20

1. jqgrid 다운로드 받기


http://www.trirand.com/blog/?page_id=6 사이트로 이동



다운로드 받아주세요



2. jquery-ui 다운로드 받기


http://jqueryui.com/download/ 사이트로 이동


다운로드 받아주세요


3. jqgrid, jquery-ui 등록시켜주기


저는 폴더를 이렇게 주어서 등록하였습니다.


1
2
3
4
5
6
7
8
<link href="<c:url value="/resources/jquery-ui/jquery-ui.css"/>" rel="stylesheet" type="text/css"/>
<link href="<c:url value="/resources/jqGrid/css/ui.jqgrid.css"/>" rel="stylesheet" type="text/css"/>
 
<script src="<c:url value="/resources/jqGrid/js/jquery-1.11.0.min.js"/>"></script>
<script src="<c:url value="/resources/jquery-ui/jquery-ui.js"/>"></script>
<script src="<c:url value="/resources/js/jquery.layout.js"/>"></script>
<script src="<c:url value="/resources/jqGrid/js/i18n/grid.locale-en.js"/>"></script>
<script src="<c:url value="/resources/jqGrid/js/jquery.jqGrid.min.js"/>"></script>
cs



(예제 1) 로컬 데이터로 출력하기


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<script>
//jqgrid 껍데기 선언
 
jQuery("#list").jqGrid({     
    datatype: "local"//데이터타입
    height: 250// 높이
       colNames:['Inv No','Date''Client''Amount','Tax','Total','Notes'], 
       colModel:[
           {name:'id',index:'id', width:60, sorttype:"int"},
           {name:'invdate',index:'invdate', width:90, sorttype:"date"},
           {name:'name',index:'name', width:100},
           {name:'amount',index:'amount', width:80, align:"right",sorttype:"float"},
           {name:'tax',index:'tax', width:80, align:"right",sorttype:"float"},        
           {name:'total',index:'total', width:80,align:"right",sorttype:"float"},        
           {name:'note',index:'note', width:150, sortable:false}        
       ],
       multiselect: true//체크박스 및 다중 선택 기능 활성화
       caption: "Manipulating Array Data" // 제목
});
var mydata = [
        {id:"1",invdate:"2007-10-01",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
        {id:"2",invdate:"2007-10-02",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
        {id:"3",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
        {id:"4",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
        {id:"5",invdate:"2007-10-05",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
        {id:"6",invdate:"2007-09-06",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
        {id:"7",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
        {id:"8",invdate:"2007-10-03",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
        {id:"9",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"}
        ];
// 데이터 하드코딩 후 껍데기에 채워줌
for(var i=0;i<=mydata.length;i++)
    jQuery("#list4").jqGrid('addRowData',i+1,mydata[i]);
 
</script>
<body>
    <table id="list"></table>
</body>
cs