본문 바로가기
IT

RealGrid 리얼그리드 기초

by 달남 2019. 9. 18.

1. 필수 선언

<script type="text/javascript">
    // 리얼그리드용 필수변수 
    var gridView;
    var dataProvider;
    var gridData;
    var realGridWrapper;
    

    // 필드 없이는 데이터 연결이 안됨
    var fields = [
                  { fieldName: "schl_id" }
                  ,{ fieldName: "schl_div_nm" }
                  ,{ fieldName: "schl_full_nm" }
                  ,{ fieldName: "zn_nm" }
                  ,{ fieldName: "mjr_cnt" }
                  ,{ fieldName: "clgcp_div_nm" }
                  ,{ fieldName: "schl_estb_div_nm" }
                  ,{ fieldName: "schl_knd_nm" }
                  ,{ fieldName: "schl_mjr_id" }
                  ,{ fieldName: "mjr_nm" }
                  ,{ fieldName: "schl_div_cd" }
                  ,{ fieldName: "mjr_id" }
              ];
    
    var columns = [
                    
                    {  name: "col1",
                        fieldName: "schl_div_nm",
                        header : { text: "<spring:message code="code.m00739" />" } //학교종류 
                        ,styles: { "textAlignment": "center" }
                        //,readOnly: "true"
                        //,width: 300
                    }
                    ,{  name: "col2"
                        ,fieldName: "schl_full_nm"
                        ,header : { text: "<spring:message code="code.m00731" />" } //학교명
                        //,styles: { "textAlignment": "center" },
                        //,readOnly: "true"
                        //,width: 300
                    }
                    ,{  name: "col3"
                        ,fieldName: "zn_nm"
                        ,header : { text: "<spring:message code="code.m00636" />" } //지역
                        ,styles: { "textAlignment": "center" }
                        //,readOnly: "true"
                        //,width: 300
                    }
                     ,{  name: "col4",
                        fieldName: "clgcp_div_nm",
                        header : { text: "<spring:message code="code.m20076" />" }  //본분교
                        ,styles: { "textAlignment": "center" }
                        //,readOnly: "true"
                        //,width: 300
                    }, 
                     <c:if test="${pramMap.gubun eq 'schl' }"> 
                        {  name: "col5",
                            fieldName: "schl_knd_nm",
                            readOnly: "true",
                            header: { text: "<spring:message code="code.m00405"/>" } //설립유형   
                            ,styles: { "textAlignment": "center" }
                        },
                        {  name: "col6",
                            fieldName: "mjr_cnt",
                            header : { text: "<spring:message code="code.m00348" />" } // 보유학과
                            ,styles: { "textAlignment": "center" }
                            //,readOnly: "true"
                            //,width: 300
                        },
                    </c:if>
                    <c:if test="${pramMap.gubun eq 'mjr' }">
                        {
                            name: "col7",
                            fieldName: "mjr_nm",
                            readOnly: "true",
                            header: {
                                text: "<spring:message code="code.m00718"/>"   //학과명
                            }
                        },
                        {  name: "col5",
                            fieldName: "schl_knd_nm",
                            readOnly: "true",
                            header: { text: "<spring:message code="code.m00405"/>" } //설립유형   
                            ,styles: { "textAlignment": "center" }
                        },
                    </c:if> 
                    {
                        name: "schl_id",
                        fieldName: "schl_id",
                        visible: false
                        //visible: true
                    }
                  
                    
                 ];
    
    
    function setRealgrid(dataResultList){
        /**
        param1 : 그리드를 표시할 div ID
        param2 : 바인드될 데이터 컬럼 정의 JSON TYPE
        param3 : 그리드 컬럼 스타일 및 param2와 연결 정보 등등... JSON TYPE
        param4 : 그리드에 표현 될 데이터 JSON TYPE
        */
        //if( realGridWrapper == null ){
        realGridWrapper = new RealGridWrapper("realgrid", fields, columns, gridData);
        gridView = realGridWrapper.getGridView();
        dataProvider = realGridWrapper.getDataProvider();
        //}
        dataProvider.setRows(dataResultList);   
        
        
      //행 삽입과 행 추가, 행 삭제가 가능하도록 옵션 조정
        gridView.setEditOptions({
        //    insertable: true,
         //   appendable: true,
            deletable: true,
            deleteRowsConfirm : false  // false 지울때 확인 메세지 끄기
        })

        //데이터를 바로 삭제하지 않고 상태만 변경
        dataProvider.setOptions({
            softDeleting: false // false 바로 삭제
        })

    }
 
       $(document).ready(function() { 
           
     
     });

</script>

댓글