본문 바로가기
IT/xPlatform

xPlatform 동적 그리드 생성하기

by heavenLake 2020. 6. 1.
반응형

 

동적으로 컬럼을 생성해주는 그리드 초기모습
1,2 번째 버튼을 클릭시 위와 같이 동적으로 컬럼이 생성된다.

 

위에 보이는 첫번째 버튼은 Xml 형태로 그리드를 생성하는 법이고

                 두번째 버튼은 그리드에 속성 함수들을 이용해 생성하는 법이다.

 

- 주요 함수

setFormatColProperty : 그리드에 현재 설정된 Format Columns의 각 열의 속성값을 설정하는 메소드입니다

                               ex.  setFormatColProperty(i,"size",nColSize);

setCellProperty          : 해당 영역에서 지정한 셀의 속성에 값을 설정하는 메소드입니다.

                              ex.   setCellProperty("body", i, "displaytype", "normal");

mergeContentsCell     : 그리드의 현재 Format 콘텐츠에 주어진 셀들을 합쳐서 하나의 셀로 만드는 메소드입니다.

appendContentsCol    : 그리드의 현재 Format 콘텐츠에 1개의 열을 추가하는 메소드입니다.

 

<?xml version="1.0" encoding="utf-8"?>
<FDL version="1.5">
  <TypeDefinition url="..\..\default_typedef.xml"/>
  <Form classname="Sample_Move_Scroll" id="Sample_Move_Scroll" inheritanceid="" position="absolute 0 0 1024 768" titletext="그리드 가변컬럼">
    <Layouts>
      <Layout>
        <Grid taborder="0" binddataset="ds_List" id="grd_Sample" cellsizingtype="col" position="absolute 24 72 992 360">
          <Formats>
            <Format id="default">
              <Columns>
                <Column size="80"/>
                <Column size="100"/>
              </Columns>
              <Rows>
                <Row band="head" size="23"/>
                <Row band="head" size="23"/>
                <Row size="20"/>
              </Rows>
              <Band id="head">
                <Cell colspan="2" rowspan="2" text="구분"/>
              </Band>
              <Band id="body">
                <Cell suppress="1" text="bind:BRANCH"/>
                <Cell col="1" text="bind:GUBUN"/>
              </Band>
            </Format>
          </Formats>
        </Grid>
        <Button id="Button00" onclick="Button00_onclick" position="absolute 527 17 647 67" taborder="1" text="실행 (Script)"/>
        <Button id="Button01" taborder="2" onclick="Button01_onclick" position="absolute 662 16 782 66" text="실행 (Method)"/>
        <Button id="Button02" taborder="3" position="absolute 798 16 918 66" onclick="Button02_onclick" text="bind 변경 Test"/>
        <TextArea id="TextArea00" taborder="4" scrollbars="autoboth" position="absolute 24 385 993 678"/>
      </Layout>
    </Layouts>
    <Objects>
      <Dataset enableevent="true" firefirstcount="0" firenextcount="0" preload="true" updatecontrol="true" useclientlayout="false" id="ds_List">
        <ColumnInfo>
          <Column id="BRANCH" size="256" type="STRING"/>
          <Column id="GUBUN" size="256" type="STRING"/>
          <Column id="COL_200807" size="256" type="STRING"/>
          <Column id="COL_200808" size="256" type="STRING"/>
          <Column id="COL_200809" size="256" type="STRING"/>
          <Column id="COL_200810" size="256" type="STRING"/>
          <Column id="COL_200811" size="256" type="STRING"/>
          <Column id="COL_200812" size="256" type="STRING"/>
          <Column id="COL_200901" size="256" type="STRING"/>
          <Column id="COL_200902" size="256" type="STRING"/>
          <Column id="COL_200903" size="256" type="STRING"/>
          <Column id="COL_200904" size="256" type="STRING"/>
          <Column id="COL_200905" size="256" type="STRING"/>
          <Column id="COL_200906" size="256" type="STRING"/>
          <Column id="COL_200907" size="256" type="STRING"/>
          <Column id="COL_TEST" size="256" type="STRING"/>
        </ColumnInfo>
        <Rows>
          <Row>
            <Col id="BRANCH">전체</Col>
            <Col id="GUBUN">A</Col>
            <Col id="COL_200807">1</Col>
            <Col id="COL_200808">2</Col>
            <Col id="COL_200809">3</Col>
            <Col id="COL_200810">4</Col>
            <Col id="COL_200811">5</Col>
            <Col id="COL_200812">6</Col>
            <Col id="COL_200901">7</Col>
            <Col id="COL_200902">8</Col>
            <Col id="COL_200903">9</Col>
            <Col id="COL_200904">10</Col>
            <Col id="COL_200905">11</Col>
            <Col id="COL_200906">12</Col>
            <Col id="COL_200907">13</Col>
            <Col id="COL_TEST">bind 테스트1</Col>
          </Row>
          <Row>
            <Col id="BRANCH">전체</Col>
            <Col id="GUBUN">B</Col>
            <Col id="COL_200807">1</Col>
            <Col id="COL_200808">2</Col>
            <Col id="COL_200809">3</Col>
            <Col id="COL_200810">4</Col>
            <Col id="COL_200811">5</Col>
            <Col id="COL_200812">6</Col>
            <Col id="COL_200901">7</Col>
            <Col id="COL_200902">8</Col>
            <Col id="COL_200903">9</Col>
            <Col id="COL_200904">10</Col>
            <Col id="COL_200905">11</Col>
            <Col id="COL_200906">12</Col>
            <Col id="COL_200907">13</Col>
            <Col id="COL_TEST">bind 테스트2</Col>
          </Row>
          <Row>
            <Col id="BRANCH">전체</Col>
            <Col id="GUBUN">C</Col>
            <Col id="COL_200807">1</Col>
            <Col id="COL_200808">2</Col>
            <Col id="COL_200809">3</Col>
            <Col id="COL_200810">4</Col>
            <Col id="COL_200811">5</Col>
            <Col id="COL_200812">6</Col>
            <Col id="COL_200901">7</Col>
            <Col id="COL_200902">8</Col>
            <Col id="COL_200903">9</Col>
            <Col id="COL_200904">10</Col>
            <Col id="COL_200905">11</Col>
            <Col id="COL_200906">12</Col>
            <Col id="COL_200907">13</Col>
            <Col id="COL_TEST">bind 테스트3</Col>
          </Row>
          <Row>
            <Col id="BRANCH">전체</Col>
            <Col id="GUBUN">B-C</Col>
            <Col id="COL_200807">1</Col>
            <Col id="COL_200808">2</Col>
            <Col id="COL_200809">3</Col>
            <Col id="COL_200810">4</Col>
            <Col id="COL_200811">5</Col>
            <Col id="COL_200812">6</Col>
            <Col id="COL_200901">7</Col>
            <Col id="COL_200902">8</Col>
            <Col id="COL_200903">9</Col>
            <Col id="COL_200904">10</Col>
            <Col id="COL_200905">11</Col>
            <Col id="COL_200906">12</Col>
            <Col id="COL_200907">13</Col>
            <Col id="COL_TEST">bind 테스트4</Col>
          </Row>
          <Row>
            <Col id="BRANCH">강남지점</Col>
            <Col id="GUBUN">A</Col>
            <Col id="COL_200807">1</Col>
            <Col id="COL_200808">2</Col>
            <Col id="COL_200809">3</Col>
            <Col id="COL_200810">4</Col>
            <Col id="COL_200811">5</Col>
            <Col id="COL_200812">6</Col>
            <Col id="COL_200901">7</Col>
            <Col id="COL_200902">8</Col>
            <Col id="COL_200903">9</Col>
            <Col id="COL_200904">10</Col>
            <Col id="COL_200905">11</Col>
            <Col id="COL_200906">12</Col>
            <Col id="COL_200907">13</Col>
            <Col id="COL_TEST">bind 테스트5</Col>
          </Row>
          <Row>
            <Col id="BRANCH">강남지점</Col>
            <Col id="GUBUN">B</Col>
            <Col id="COL_200807">1</Col>
            <Col id="COL_200808">2</Col>
            <Col id="COL_200809">3</Col>
            <Col id="COL_200810">4</Col>
            <Col id="COL_200811">5</Col>
            <Col id="COL_200812">6</Col>
            <Col id="COL_200901">7</Col>
            <Col id="COL_200902">8</Col>
            <Col id="COL_200903">9</Col>
            <Col id="COL_200904">10</Col>
            <Col id="COL_200905">11</Col>
            <Col id="COL_200906">12</Col>
            <Col id="COL_200907">13</Col>
            <Col id="COL_TEST">bind 테스트6</Col>
          </Row>
          <Row>
            <Col id="BRANCH">강남지점</Col>
            <Col id="GUBUN">C</Col>
            <Col id="COL_200807">1</Col>
            <Col id="COL_200808">2</Col>
            <Col id="COL_200809">3</Col>
            <Col id="COL_200810">4</Col>
            <Col id="COL_200811">5</Col>
            <Col id="COL_200812">6</Col>
            <Col id="COL_200901">7</Col>
            <Col id="COL_200902">8</Col>
            <Col id="COL_200903">9</Col>
            <Col id="COL_200904">10</Col>
            <Col id="COL_200905">11</Col>
            <Col id="COL_200906">12</Col>
            <Col id="COL_200907">13</Col>
            <Col id="COL_TEST">bind 테스트7</Col>
          </Row>
          <Row>
            <Col id="BRANCH">강남지점</Col>
            <Col id="GUBUN">B-C</Col>
            <Col id="COL_200807">1</Col>
            <Col id="COL_200808">2</Col>
            <Col id="COL_200809">3</Col>
            <Col id="COL_200810">4</Col>
            <Col id="COL_200811">5</Col>
            <Col id="COL_200812">6</Col>
            <Col id="COL_200901">7</Col>
            <Col id="COL_200902">8</Col>
            <Col id="COL_200903">9</Col>
            <Col id="COL_200904">10</Col>
            <Col id="COL_200905">11</Col>
            <Col id="COL_200906">12</Col>
            <Col id="COL_200907">13</Col>
            <Col id="COL_TEST">bind 테스트8</Col>
          </Row>
          <Row>
            <Col id="BRANCH">중앙지점</Col>
            <Col id="GUBUN">A</Col>
            <Col id="COL_200807">1</Col>
            <Col id="COL_200808">2</Col>
            <Col id="COL_200809">3</Col>
            <Col id="COL_200810">4</Col>
            <Col id="COL_200811">5</Col>
            <Col id="COL_200812">6</Col>
            <Col id="COL_200901">7</Col>
            <Col id="COL_200902">8</Col>
            <Col id="COL_200903">9</Col>
            <Col id="COL_200904">10</Col>
            <Col id="COL_200905">11</Col>
            <Col id="COL_200906">12</Col>
            <Col id="COL_200907">13</Col>
            <Col id="COL_TEST">bind 테스트9</Col>
          </Row>
          <Row>
            <Col id="BRANCH">중앙지점</Col>
            <Col id="GUBUN">B</Col>
            <Col id="COL_200807">1</Col>
            <Col id="COL_200808">2</Col>
            <Col id="COL_200809">3</Col>
            <Col id="COL_200810">4</Col>
            <Col id="COL_200811">5</Col>
            <Col id="COL_200812">6</Col>
            <Col id="COL_200901">7</Col>
            <Col id="COL_200902">8</Col>
            <Col id="COL_200903">9</Col>
            <Col id="COL_200904">10</Col>
            <Col id="COL_200905">11</Col>
            <Col id="COL_200906">12</Col>
            <Col id="COL_200907">13</Col>
            <Col id="COL_TEST">bind 테스트10</Col>
          </Row>
          <Row>
            <Col id="BRANCH">중앙지점</Col>
            <Col id="GUBUN">C</Col>
            <Col id="COL_200807">1</Col>
            <Col id="COL_200808">2</Col>
            <Col id="COL_200809">3</Col>
            <Col id="COL_200810">4</Col>
            <Col id="COL_200811">5</Col>
            <Col id="COL_200812">6</Col>
            <Col id="COL_200901">7</Col>
            <Col id="COL_200902">8</Col>
            <Col id="COL_200903">9</Col>
            <Col id="COL_200904">10</Col>
            <Col id="COL_200905">11</Col>
            <Col id="COL_200906">12</Col>
            <Col id="COL_200907">13</Col>
            <Col id="COL_TEST">bind 테스트11</Col>
          </Row>
          <Row>
            <Col id="BRANCH">중앙지점</Col>
            <Col id="GUBUN">B-C</Col>
            <Col id="COL_200807">1</Col>
            <Col id="COL_200808">2</Col>
            <Col id="COL_200809">3</Col>
            <Col id="COL_200810">4</Col>
            <Col id="COL_200811">5</Col>
            <Col id="COL_200812">6</Col>
            <Col id="COL_200901">7</Col>
            <Col id="COL_200902">8</Col>
            <Col id="COL_200903">9</Col>
            <Col id="COL_200904">10</Col>
            <Col id="COL_200905">11</Col>
            <Col id="COL_200906">12</Col>
            <Col id="COL_200907">13</Col>
            <Col id="COL_TEST">bind 테스트12</Col>
          </Row>
        </Rows>
      </Dataset>
      <Dataset enableevent="true" firefirstcount="0" firenextcount="0" preload="true" updatecontrol="true" useclientlayout="false" id="ds_DispDate">
        <ColumnInfo>
          <Column id="YYYYMM" size="256" type="STRING"/>
          <Column id="DISP_HEAD1" size="256" type="STRING"/>
          <Column id="DISP_HEAD2" size="256" type="STRING"/>
        </ColumnInfo>
        <Rows>
          <Row>
            <Col id="YYYYMM">200807</Col>
            <Col id="DISP_HEAD1">08년 3분기</Col>
            <Col id="DISP_HEAD2">7월</Col>
          </Row>
          <Row>
            <Col id="YYYYMM">200808</Col>
            <Col id="DISP_HEAD1">08년 3분기</Col>
            <Col id="DISP_HEAD2">8월</Col>
          </Row>
          <Row>
            <Col id="YYYYMM">200809</Col>
            <Col id="DISP_HEAD1">08년 3분기</Col>
            <Col id="DISP_HEAD2">9월</Col>
          </Row>
          <Row>
            <Col id="YYYYMM">200810</Col>
            <Col id="DISP_HEAD1">08년 4분기</Col>
            <Col id="DISP_HEAD2">10월</Col>
          </Row>
          <Row>
            <Col id="YYYYMM">200811</Col>
            <Col id="DISP_HEAD1">08년 4분기</Col>
            <Col id="DISP_HEAD2">11월</Col>
          </Row>
          <Row>
            <Col id="YYYYMM">200812</Col>
            <Col id="DISP_HEAD1">08년 4분기</Col>
            <Col id="DISP_HEAD2">12월</Col>
          </Row>
          <Row>
            <Col id="YYYYMM">200812</Col>
            <Col id="DISP_HEAD1">08년 4분기</Col>
            <Col id="DISP_HEAD2">13월</Col>
          </Row>
          <Row>
            <Col id="YYYYMM">200901</Col>
            <Col id="DISP_HEAD1">09년 1분기</Col>
            <Col id="DISP_HEAD2">1월</Col>
          </Row>
          <Row>
            <Col id="YYYYMM">200902</Col>
            <Col id="DISP_HEAD1">09년 1분기</Col>
            <Col id="DISP_HEAD2">2월</Col>
          </Row>
          <Row>
            <Col id="YYYYMM">200903</Col>
            <Col id="DISP_HEAD1">09년 1분기</Col>
            <Col id="DISP_HEAD2">3월</Col>
          </Row>
          <Row>
            <Col id="YYYYMM">200904</Col>
            <Col id="DISP_HEAD1">09년 2분기</Col>
            <Col id="DISP_HEAD2">4월</Col>
          </Row>
          <Row>
            <Col id="YYYYMM">200905</Col>
            <Col id="DISP_HEAD1">09년 2분기</Col>
            <Col id="DISP_HEAD2">5월</Col>
          </Row>
          <Row>
            <Col id="YYYYMM">200906</Col>
            <Col id="DISP_HEAD1">09년 2분기</Col>
            <Col id="DISP_HEAD2">6월</Col>
          </Row>
          <Row>
            <Col id="YYYYMM">200907</Col>
            <Col id="DISP_HEAD1">09년 3분기</Col>
            <Col id="DISP_HEAD2">7월</Col>
          </Row>
        </Rows>
      </Dataset>
    </Objects>
    <Script type="xscript4.0"><![CDATA[
function Button00_onclick(obj:Button,  e:ClickEventInfo)
{
	var v_Formats = "";
	var v_Columns = "";
	var v_Rows = "";
	var v_BandHead = "";
	var v_BandBody = "";

	v_Columns += '<Column size="80" />\n';
	v_Columns += '<Column size="100" />\n';
	
	v_Rows += '<Row size="23" band="head" />\n';
	v_Rows += '<Row size="23" band="head" />\n';
	v_Rows += '<Row size="20" />\n';
	
	v_BandHead += '<Cell rowspan="2" colspan="2" text="구분"/>\n';
	
	v_BandBody += '<Cell text="bind:BRANCH" suppress="1"/>\n';
	v_BandBody += '<Cell col="1" text="bind:GUBUN"/>\n';
	
	// 포맷 생성
	var v_HeadText = "";
	var v_HeadColIdx = 2;
	var v_BodyColIdx = 2;
	
	for (var i=0; i<ds_DispDate.getRowCount(); i++) {
		
		// Column 생성
		v_Columns += '<Column size="60" />\n';

		// Head 생성
		if (v_HeadText != ds_DispDate.getColumn(i, "DISP_HEAD1")) {
			v_HeadText = ds_DispDate.getColumn(i, "DISP_HEAD1");
			
			var v_Colspan = ds_DispDate.getCaseCount("DISP_HEAD1=='" + v_HeadText + "'");
			
			// Row 1
			v_BandHead += '<Cell col="'+v_HeadColIdx+'" colspan="'+v_Colspan+'" text="'+v_HeadText+'"/>\n';
			
			// Row 2
			for (var j=i; j<ds_DispDate.getRowCount(); j++) {
				if (v_HeadText == ds_DispDate.getColumn(j, "DISP_HEAD1")) {
					v_BandHead += '<Cell row="1" col="'+v_HeadColIdx+'" text="'+ds_DispDate.getColumn(j, "DISP_HEAD2")+'"/>\n';
					v_HeadColIdx++;
				}
			}
		}
		
		// Body 생성
		v_BandBody += '<Cell style="align:right;" col="'+v_BodyColIdx+'" displaytype="number" text="bind:COL_'+ds_DispDate.getColumn(i, "YYYYMM")+'"/>\n';
		v_BodyColIdx++;
	}

	v_Formats = '<Formats>\n';
	v_Formats += '<Format id="default">\n';
	v_Formats += '<Columns>\n';
	v_Formats += v_Columns;
	v_Formats += '</Columns>\n';
	v_Formats += '<Rows>\n';
	v_Formats += v_Rows;
	v_Formats += '</Rows>\n';
	v_Formats += '<Band id="head">\n';
	v_Formats += v_BandHead;
	v_Formats += '</Band>\n';	
	v_Formats += '<Band id="body">\n';
	v_Formats += v_BandBody;
	v_Formats += '</Band>\n';		
	v_Formats += '</Format>\n';	
	v_Formats += '</Formats>\n';
	
	//trace(v_Formats);
	grd_Sample.enableredraw = false;
	grd_Sample.formats = v_Formats;
	grd_Sample.enableredraw = true;
	
	TextArea00.value = grd_Sample.getCurFormatString();
}

function Button01_onclick(obj:Button,  e:ClickEventInfo)
{	
	var v_StartCol = 2;
	var v_StartCell = 2;
	
	// 기본컬럼을 제외하고 삭제
	for (var i=grd_Sample.getCellCount("body"); i>1; i--) {
		grd_Sample.deleteContentsCol("body",i,false);
	}
	
	// 컬럼 추가
	for (var i=0; i<ds_DispDate.getRowCount(); i++) {
		grd_Sample.appendContentsCol(false);
	}
	
	// Head 1 Level - Merge Cell
	var v_CellIdx = v_StartCell;
	for (var i=v_StartCell; i<grd_Sample.getCellCount("body"); i=i+3) {
		grd_Sample.mergeContentsCell("head",0,i,0,i+2,v_CellIdx,false);		
		v_CellIdx++;
	}
	
	// Head 1 Level - Set Text
	v_CellIdx = 1;
	for (var i=0; i<ds_DispDate.getRowCount(); i=i+3) {
		grd_Sample.setCellProperty("head", v_CellIdx, "text", ds_DispDate.getColumn(i, "DISP_HEAD1"));
		v_CellIdx++;
	}
	
	// 컬럼 넓이 지정 & Text 지정 & Column binding
	for (var i=v_StartCol; i<grd_Sample.getCellCount("body"); i++) {
		//grd_Sample.setRealColSize(i, 60, true);
		grd_Sample.setFormatColProperty(i,"size",60);
		grd_Sample.setCellProperty("head", v_CellIdx, "text", ds_DispDate.getColumn(i-v_StartCol, "DISP_HEAD2"));
		
		//grd_Sample.setCellProperty("body", i, "displaytype", "number");
		//grd_Sample.setCellProperty("body", i, "style", "align:right;");
		grd_Sample.setCellProperty("body", i, "text", "bind:COL_" + ds_DispDate.getColumn(i-v_StartCol, "YYYYMM"));
		v_CellIdx++;
	}	
	
	TextArea00.value = grd_Sample.getCurFormatString();
}

function Button02_onclick(obj:Button,  e:ClickEventInfo)
{
	// Design 때 생성한 Cell의 bind 정보 변경 ==> OK
	grd_Sample.setCellProperty("body", 1, "text", "bind:COL_TEST");
	
	// Runtime 때 생성한 Cell의 bind 정보 변경 ==> FAIL
	grd_Sample.setCellProperty("body", 2, "text", "bind:COL_TEST");	
}
]]></Script>
  </Form>
</FDL>

반응형

댓글