SBGrid는 사용자 정의 함수를 통한 수식 계산 기능을 제공합니다.


요약

callback 을 사용할수 있게 하여 수식계산 기능이 가능한 사용자 정의 함수를 제공합니다.

입력값

"calc" : "sum()" 컬럼정보를 담고 있는 오브젝트의 해당 컬럼에 사용자정의함수를 추가합니다.


예) datagrid2.addColumn("ref:average; type:output; calc:sum(); text-align:right");
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page language="java"   contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html xmlns="http://www.w3.org/1999/xhtml" lang="ko" xml:lang="ko">
<head>
	<meta content="IE=9" http-equiv="X-UA-Compatible">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>SoftBowl SBGrid Example</title>
	<script type="text/javascript" src="../../kr/co/softbowl/js/Library/json-minified.js"></script>
	<script type="text/javascript" src="../../js/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="../../kr/co/softbowl/js/Library/json2.js"></script>
		
	<script type="text/javascript" src="../../kr/co/softbowl/SBGrid.js"></script>
	
	<script type="text/javascript" src="../../js/DATA_World_Bank_Statistics_small.js"></script>
		
	<script type="text/javascript">			
		SBGrid.DEF.DOMAIN = "../../";
	<script>
	
	<script type="text/javascript">
		var datagrid1;
		function __createElements (){
			var objJson = 	{																	
								        "strParentId" : "sbGridArea",
								        "strId": "datagrid1",
								        "strCaption": "Year^CO2 emissions^Electric power consumption",
								        "strColWidth": "100,140,238",
								        "strJsonRef": "grid_data",
								        "strStyle": "width:700px; height:265px; ",
								        "bAutoResize" : true,
								        "strRowHeader" : "seq"
					};
										
			datagrid1 = createSBDataGrid(objJson);
			var objCol =	[
									{
										"id": "col2",
										"type": "output",
										"ref": "Year",
										"style" : "text-align:center"
									},
									{
										"id": "col3",
										"type": "output",
										"ref": "CO2emissions"
									},
									{
										"id": "col4",
										"type": "output",
										"ref": "Electric_power_consumption"
									}
					];
			datagrid1.createColumns(objCol);
			
			datagrid1.setRowHeight(0,60,false);
		}		
		
		function sum(strId, nRow, nCol)
		{				
			var strValue1 = "";				
			eval('strValue1 = ' + strId + '.getTextMatrix(nRow, nCol-2);');
			var strValue2 = "";
			eval('strValue2 = ' + strId + '.getTextMatrix(nRow, nCol-1);');
			var result = parseInt(strValue1) + parseInt(strValue2);
			return result.toString();
		}
		
		function average(strId, nRow, nCol)
		{
			var strValue = "";				
			eval('strValue = ' + strId + '.getTextMatrix(nRow, nCol-1);');
			var nSum = parseInt(strValue);
			var fAverage = nSum / 2;
			return parseInt(fAverage).toString();
		}
		
		var isExecutedGetTotal = false;
		function getTotal()
		{
			if (!isExecutedGetTotal)
			{
				datagrid1.addColumn("ref:total; type:output; calc:sum(); text-align:right");
				datagrid1.setCaption(datagrid1.getCaption() + "total");
				datagrid1.refresh();
				isExecutedGetTotal = true;
			}	
		}
		
		var isExecutedGetAverage = false;
		function getAverage()
		{
			if (!isExecutedGetAverage)
			{
				datagrid1.addColumn("ref:average; type:output; calc:average(); text-align:right");
				datagrid1.setCaption(datagrid1.getCaption() + "average");
				datagrid1.refresh();
				
				isExecutedGetAverage = true;
			}				
		}
	</script>
</head> 
<body onload="__createElements()" class="sbgrid_body">
	
    <div id="button_group">
    <input type="button" class="sbgrid_demo_button" style="width:700px; height:30px;" id="button_subtotal" value="행 별 합계 및 평균 구하기" onclick="getTotal();getAverage();datagrid1.refresh();"></input>
    </div>
    <div class="content_group">
        <div id="sbGridArea" style="width:700px;"></div>
    </div>
    
</body>
</html>