레이블이 jqGrid인 게시물을 표시합니다. 모든 게시물 표시
레이블이 jqGrid인 게시물을 표시합니다. 모든 게시물 표시

2012-11-23

jquery] jquery jqgrid 설정



원본 출처 : http://dayg.tistory.com/239?srchid=BR1http%3A%2F%2Fdayg.tistory.com%2F239


http://www.trirand.com/blog/?page_id=6 에서 기능별 js파일을 선택하여 zip파일 다운로드.

압축을 풀면 세가지 폴더가 나온다.

jquery.jqGrid-3.6.5/js : 
jquery.jqGrid.min.js - jqGrid의 모든 기능이 포함된 압축버전, 배포시 사용
/i18n/grid.locale-en.js - 언어별 locale파일이 있는 i18n폴더. 난 rid.locale-en.js파일을 사용했다.

jquery.jqGrid-3.6.5/css: grid에서 사용하는 css


jquery.jqGrid-3.6.5/src: src폴더는 디버깅을 위한 비압축된 기능별 스크립트 파일이 포함되어있다. 개발시 사용

jqGrid 디버깅을 위한 설정

jquery.jqGrid-3.6.5/src/grid.loader.js
- 비압축된 js파일들을 include해주는 스크립트다. 소스에서 pathtojsfiles라는 변수에 src폴더의 js파일들의 경로를      설정하고, 이 파일을 include하면 된다.
 

메시지: '$.jgrid.formatter.integer'은(는) null 이거나 개체가 아닙니다.
줄: 711
문자: 5
코드: 0

위 에러는 locale파일의 경로가 틀렸을 경우에 발생한다. 

jquery] jqgrid 속성들



출처 : http://devildung.springnote.com/pages/4796171

jQuery('#grid_selector').jqGrid( options )

options에 해당하는 속성들.

Property
Description
url
tells us where to get the data. Typically this is a server-side function with a connection to a database which returns the appropriate information to be filled into the Body layer in the grid
- 데이터를 가지고 와야할 url을 지정하는 곳. DB연결 동시에 적합한 정보를 body부분의 grid에 채워주는 server-side 기능이다.
datatype
this tells jqGrid the type of information being returned so it can construct the grid. In this case we tell the grid that we expect xml data to be returned from the server, but other formats are possible. For a list of all available datatypes refer to API Methods
- grid가 생성될때 리턴된 정보의 타입을 적는 곳. 이 경우 서버로부터 xml 데이터를 가져와 처리가능하고 다른 형식(타입)도 가능하다. 자세한 것은 API 메소드 보고 알아서 하라.
mtype
tells us how to make the ajax call: either 'GET' or 'POST'. In this case we will use the GET method to retrieve data from the server
- GET 방식으로 호출할지 POST로 호출할지를 적는 곳. 대부분 GET으로 이용한다.
colNames
an array in which we place the names of the columns. This is the text that appears in the head of the grid (Header layer). The names are separated with commas
- 컬럼의 이름을 지정하는 곳. Header Layer에 표시된다.
colModel
an array that describes the model of the columns. This is the most important part of the grid. Here I explain only the options used above. For the complete list of options see colModel API:
name
the name of the column. This name does not have to be the name from database table, but later we will see how we can use this when we have different data formats
- 컬럼의 이름. 이름은 DB Table의 이름이 될 수 없으며, 추후 서로 다른 타입의 데이터 타입의 정보를 가지고 있을때 어떻게 사용할 수 있는지 볼 수 있다.
index
the name passed to the server on which to sort the data (note that we could pass column numbers instead). Typically this is the name (or names) from database -- this is server-side sorting, so what you pass depends on what your server expects to receive
- 데이터 정렬을 위한 인덱스. (DB의 테이블의 컬럼명을 따른다.)
width
the width of the column, in pixels
align
the alignment of the column
sortable
specifies if the data in the grid can be sorted on this column; if false, clicking on the header has no effect
pager
defines that we want to use a pager bar to navigate through the records. This must be a valid html element; in our example we gave the div the id of "pager", but any name is acceptable. Note that the Navigation layer (the "pager" div) can be positioned anywhere you want, determined by your html; in our example we specified that the pager will appear after the Body layer.
- 여러 데이터를 페이지 bar 하기 위해 선언하는 것. 반드시 유효한 element 여야 한다.
Navigation layer( Div : pager ) 를 이용하여 원할때 어디서든지 사용 가능하다.
rowNum
sets how many records we want to view in the grid. This parameter is passed to the url for use by the server routine retrieving the data
- grid에 몇개의 데이터를 보여 줄 것인지 지정 하는 것.
rowList
an array to construct a select box element in the pager in which we can change the number of the visible rows. When changed during the execution, this parameter replaces the rowNum parameter that is passed to the url
- pager의 select box가 생성될때 배열로 볼수 있는 데이터의 수를 지정한다. 갯수가 바뀌어 실행이 되면 rowNum 파라미터가 자동적으로 바뀌게 되어 url로 전송이 되어 다시 데이터를 가져온다.
sortname
sets the initial sorting column. Can be a name or number. This parameter is added to the url for use by the server routine
- 초기화 될때 sort할 컬럼을 지정한다. 숫자 or 컬럼 이름일 수 있고, 서버 루틴 사용을 위한 파라미터에 추가되는 것(?)
sortorder
sets the sorting order. This parameter is added to the url
- 정렬 방법 (desc | asc)
viewrecords
defines whether we want to display the number of total records from the query in the pager bar
- 총 레코드 수를 pager bar에 표시할 것 인지 지정하는 것.
imgpath
the path to the images needed for the grid. The path should not end with '/'
- 생략
caption
sets the caption for the grid. If this parameter is not set the Caption layer will be not visible
- Grid의 제목을 설정하는 것. 이 부분이 없으면 제목은 보여지지 않는다.



jquery] jqgrid 예제




출처 : http://kdonghwa.tistory.com/185

파일 : jQueryGrid.zip

jQuery로 프로젝트 수행중 extjs의 grid기능을 맘껏 쓸수 없을까 하다가 데꾸벅! jqGrid라 는 아주 좋은 녀석을 발견하였다.

여러가지 테마를 사용할수 있지만 구미에 맞도록 CSS를 바꿔 보았다. extjs의 경우 UI자체를 수정하기가 어려운 반면 이녀석은 상당히 수월하게 바꿀수 있었다.







HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>서학리조트 컨텐츠</title>
<link rel="stylesheet" type="text/css" href="style/css/contents.css" media="screen" />
<link rel="stylesheet" type="text/css" href="style/css/grid.css" media="screen" />
<script type="text/javascript" src="style/js/jquery.js" charset="utf-8"></script>
<script type="text/javascript" src="style/js/jquery.jqGrid.js" charset="utf-8"></script>
<script type="text/javascript" src="style/js/contents_04.js"  charset="utf-8"></script>
</head>
<body>
    <table class="tbl_tit02"><tr><td>담보 사항</td></tr></table>
    <div class="gridJ" style="width:780px"><table id="gridList" class="scroll" ></table></div>

    <div id="rsperror" title="서버에러나오는곳"></div>


    <input type="button" value="선택된Row 데이터가져오기" id="a1" />
    <input type="button" value="Row삭제" id="a2" />
    <input type="button" value="마지막Row추가" id="a3" />
    <input type="button" value="id가 13인 Row선택하기" id="a4" /><br />
    <input type="button" value="tax컬럼 숨기기" id="a5" />
    <input type="button" value="tax컬럼 나타내기" id="a6" />
    <input type="button" value="id가 13 에디팅하기" id="a7" />
    <input type="button" value="저장" id="a8" />
    <input type="button" value="취소" id="a9" /><br />
    <input type="button" value="header값 스타일변경" id="a10" />
    <input type="button" value="셀값 스타일변경" id="a11" />
    <input type="button" value="데이타초기화" id="a12" />
    <input type="button" value="그리드 width/height조절" id="a13" /><br />
  
    <input type="button" value="HTML 테이블을 그리드화하기" id="a14" />
</body>
</html>


js file
var lastsel3;
$(document).ready(function(){
    $("#gridList").jqGrid({
        url:'server.json',
        mtype: 'GET',
        datatype: "json",
        colNames:['인벤토리','날짜', '고객', '수량','세금','합계','비고'],
        colModel:[
         {name:'id',index:'id', width:100,align:"center",key:true},
         {name:'invdate',index:'invdate', width:120,editable:true,sorttype:"date",formatter:'date', formatoptions:{srcformat:"Y-m-d",newformat:"d-M-Y"}},
         {name:'name',index:'name asc, invdate', width:100,editable:true,editoptions:{size:"20",maxlength:"30"}},
         {name:'amount',index:'amount', width:100, align:"right",editable:true,editable:true,editrules:{number:true,minValue:100,maxValue:350},formatter:'currency',formatoptions:{thousandsSeparator:","}},
         {name:'tax',index:'tax', width:100, align:"right",editable:true,edittype:"select",editoptions:{value:"FE:FedEx;IN:InTime;TN:TNT;AR:ARAMEX"}},
         {name:'total',index:'total', width:100,align:"right",editable:true,edittype:"checkbox",editoptions: {value:"Yes:No"}},
         {name:'note',index:'note', width:150, sortable:false,editable:true,edittype:"textarea", editoptions:{rows:"1",cols:"20"}}
        ],
        rowNum:30,    <-- 가끔씩 이넘이 말썽부릴때가...  -1로 해놓으면 가져온 데이타 모두 뿌려줍니다
        height:278,
        sortname: 'id',
        sortorder: "desc",
        viewrecords: true,
        multiselect: false,//앞에 체크박스처리
        multikey: "",//multikey: "ctrlKey/shiftKey",
        editurl: "server.json",
        /*onSelectRow: function(id){  //row가 선택되었을 경우
      if(id && id!==lastsel3){
       jQuery('#gridList').restoreRow(lastsel3);
       jQuery('#gridList').editRow(id,true,pickdates);
       lastsel3=id;
      }
     },*/
        /*jsonReader: {//스크롤할때마다 가져오기
      repeatitems : true,
      cell:"",
      id: "0"
     },*/
       afterInsertRow: function(rowid, aData){
         switch (aData.name) {
          case 'Client 1':
           jQuery("#gridList").setCell(rowid,'total','',{color:'green'});
          break;
          case 'Client 2':
           jQuery("#gridList").setCell(rowid,'total','',{color:'red'});
          break;
          case 'Client 3':
           jQuery("#gridList").setCell(rowid,'total','',{color:'blue'});
          break;
         
         }
        },
        loadError : function(xhr,st,err) {
         jQuery("#rsperror").html("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText);
        },
        imgpath: 'style/grid'
    });
    $("#a1").click( function(){
     var id = jQuery("#gridList").getGridParam('selrow');
     if (id) {
      var ret = jQuery("#gridList").getRowData(id);
      alert("id="+ret.id+" invdate="+ret.invdate+"...");
     } else { alert("Row를 선택해주세요");}
    });
    $("#a2").click( function(){
     var su=jQuery("#gridList").delRowData(12);
     if(su) alert("id가 12인 Row삭제"); else alert("이미 지워졌삼~");
    });
    $("#a3").click( function(){
     var datarow = {id:"99",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"};
     var su=$("#gridList").addRowData(99,datarow);
     if(su) alert("마지막Row추가 성공- 서버쪽 업데이트처리해주세요"); else alert("처리가 되지 않았음.");
    });
    $("#a4").click( function() {
        $("#gridList").resetSelection();
     $("#gridList").setSelection("13");
    });
    $("#a5").click( function() {
     $("#gridList").hideCol("tax");
    });
    $("#a6").click( function() {
     $("#gridList").showCol("tax");
    });
    jQuery("#a7").click( function() {
     jQuery("#gridList").editRow("13");
     this.disabled = 'true';
     jQuery("#a8,#a9").attr("disabled",false);
    });
    jQuery("#a8").click( function() {
     jQuery("#gridList").saveRow("13");
     jQuery("#a8,#a9").attr("disabled",true);
     jQuery("#a7").attr("disabled",false);
    });
    jQuery("#a9").click( function() {
     jQuery("#gridList").restoreRow("13");
     jQuery("#a8,#a9").attr("disabled",true);
     jQuery("#a7").attr("disabled",false);
    });
    jQuery("#a10").click( function() {
     $("#gridList").setLabel("tax","Tax Amt",{'font-weight': 'bold','font-style': 'italic'});
    });
  
    jQuery("#a11").click( function() {
     $("#gridList").setCell("12","tax","",{'font-weight': 'bold',color: 'red','text-align':'center'});
    });
  
    jQuery("#a12").click( function() {
     $("#gridList").clearGridData();
    });
    jQuery("#a13").click( function() {
     $("#gridList").setGridWidth(500);
     $("#gridList").setGridHeight(400);
    });
    jQuery("#a14").click(function (){
     tableToGrid("#htmlGrid");
     $("#htmlGrid").setGridWidth(810);
    });
});

function pickdates(id){
 alert(id);
}


server.json
{
    "page": "1",
    "total": 27,
    "records": "13",
    "rows": [
        {
            "id": "5",
            "cell": [
                "5",
                "2007-10-06",
                "Client 3",
                "200.00",
                "0.00",
                "200.00",
                null
            ]
        },
        {
            "id": "4",
            "cell": [
                "4",
                "2007-10-05",
                "Client 2",
                "120.00",
                "12.00",
                "134.00",
                null
            ]
        },
        {
            "id": "3",
            "cell": [
                "3",
                "2007-10-05",
                "Client 1",
                "50.00",
                "10.00",
                "60.00",
                null
            ]
        },
        {
            "id": "2",
            "cell": [
                "2",
                "2007-10-05",
                "Client 3",
                "100.00",
                "0.00",
                "100.00",
                "no tax"
            ]
        },
        {
            "id": "1",
            "cell": [
                "1",
                "2007-10-04",
                "Client 3",
                "150.00",
                "0.00",
                "150.00",
                "no tax"
            ]
        }
    ]
}


선택된 Row
jQuery("#grid_id").getGridParam("selrow");

선택된 Row 해제
jQuery("#grid_id").resetSelection();

새 Row 선택
jQuery("#grid_id").setSelection("2");

Row 삭제
jQuery("#grid_id").delRowData("2");

Row 수정
jQuery("#grid_id").setRowData("rowid", {myname:"myvalue"});

Row 추가
addRowData( rowid, data, position, srcrowid )

myfirstrow = { invid:"1", invdate:"2007-10-01", note:"note", amount:"200.00", tax:"10.00", total:"210.00"} jQuery("#list").addRowData("1", myfirstrow);

position: 'first', 'last', 'before', 'after'
srcrowid : position이 'before', 'after'일때만 설정함

출처 : http://techbug.tistory.com/158

jquery] jqgrid plugin 사용



원본출처 :  http://dev.henjjang.com/414

jqGrid를 기억하고자 이번 포스팅을 작성한다. jqGrid 사이트 와 데모사이트를 통해서 관련된 여러정보를 얻을 수 있지만 사용했던것을 정리하지 않으면 기억했던것을 또 찾아야 하는 일이 되풀이 되곤한다.

버전

- 최근(2010.07.12)에 릴리즈 된 버전이 3.7.2 버전이다. 3.7.2 버전에서 변화된 내용은 다음에서 확인할 수 있다. 3.7 버전은 다음의 내용을 담고 있다.

 
+ Load array data at once
+ Load at once from server
+ Single search
+ Multiple search
+ Virtual scrolling
+ Toolbar search
+ Add/edit/delete on local data
 

- 2010.8월 Grouping 이 가능한 jqGrid 3.8 Beta 버전을 공개했다.



jqGrid 시작하려면

 
- jqGrid 를 시작하려면 jQuery를 알아야 한다. javascript 프레임워크, 또는 라이브러리라고 부를 수 있는 jQuery 에 대해서는 추후 정리해야겠다. 

 
<!-- BEGIN: load jQuery UI theme -->
<link type="text/css" href="./css/themes/ui-lightness/jquery-ui-1.8.2.custom.css" rel="stylesheet" /><!-- END: load jQuery UI theme -->
<!-- BEGIN: load jQuery -->
<script type="text/javascript" src="./js/jquery-1.4.2.js"></script>
<!-- END: load jquery -->

<!-- BEGIN: load jQuery UI-->
<script type="text/javascript" src="./js/jquery-ui-1.8.2.custom.min.js"></script>
<!-- END: load jQuery UI-->
 
[code 1 : jquery theme, jquery ui, jquery 선언부]

[code 1] 은 ui-lightness 테마를 적용하고, jquery ui, jquery 관련되어 선언하는 부분이다. 





jqGrid 시작하기

 
- jqGrid 시작하기


jqGrid 다루기

 
- jqGrid 다루기

* id가 13 인 값을 선택한다.
jQuery("#list9").jqGrid('setSelection',"13");<font class="Apple-style-span" color="#333333" face="굴림"><span class="Apple-style-span" style="line-height: 18px; white-space: normal;"><font class="Apple-style-span" color="#222222" face="monospace"><span class="Apple-style-span" style="line-height: 15px; white-space: pre;"><br /> </span></font></span></font>

참고사이트

 
jQuery Grid Plugin site

jquery] jqGrid 설치 시 꼭 신경써야 할 것



원본 출처 :: http://comnori.blogspot.com/2011/07/jqgrid.html



jqGrid 설치 시 꼭 신경써야 할 것


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My First Grid</title>
 
<link rel="stylesheet" type="text/css" media="screen" href="css/ui-lightness/jquery-ui-1.7.1.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
 
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
 
</head>
<body>
...
</body>
</html>

원문 사이트 : http://www.trirand.com/jqgridwiki/doku.php?id=wiki:how_to_install

1. 위에 나온 css, js 파일을 반드시 사용한다.

2. 스크립트 소스 순서는
grid.local-en.js (언어에 따라 en 부분은 바뀔 수 있음)가
jquery.jqGrid.min.js 보다 무조건 위에 선언되어야 한다.

이게 안되면 pager 부분이 작동하지 않는다.