Footer

Setting style for footer:

  • To modify default style of footer you should redefine "div.gridbox div.ftr td" after dhtmlXGrid.css has been placed on page
  • To set explicit style for each cell in footer use the second argument of attachFooter method.
</> Source
<!DOCTYPE html>
<!--pro-->
<html>
<head>
	<title>Footer</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
	<link rel="stylesheet" type="text/css" href="../../../codebase/fonts/font_roboto/roboto.css"/>
	<link rel="stylesheet" type="text/css" href="../../../codebase/dhtmlx.css"/>
	<script src="../../../codebase/dhtmlx.js"></script>
	<script>
		var myGrid;
		function doOnLoad(){
			myGrid = new dhtmlXGridObject('gridbox');
			myGrid.setImagePath("../../../codebase/imgs/");
			myGrid.setHeader("Book,#cspan,North Region,#cspan,South Region,#cspan");
			myGrid.attachHeader("Author,Title,Price,Sold,Price,Sold");
			myGrid.setInitWidths("150,170,50,80,50,*");
			myGrid.setColAlign("left,left,right,right,right,right");
			myGrid.setColTypes("ro,ro,price,ed,price,ed");
			myGrid.setColSorting("str,str,int,int,int,int");
			myGrid.attachEvent("onEditCell",calculateFooterValues);
			myGrid.enableAutoWidth(true);
			myGrid.enableAutoHeight(true);
			myGrid.init();
			myGrid.attachFooter("Total quantity,#cspan,-,<div id='nr_q'>0</div>,-,<div id='sr_q'>0</div>",["text-align:left;"]);
			myGrid.attachFooter("Income per Region,#cspan,<div id='nr_s'>0</div>,#cspan,<div id='sr_s'>0</div>,#cspan",["text-align:left;"]);
			myGrid.load("../common/grid_numbers.xml",calculateFooterValues);
		}
		function calculateFooterValues(stage){
			if(stage && stage!=2)
				return true;
			var nrQ = document.getElementById("nr_q");
				nrQ.innerHTML = sumColumn(3);
			var srQ = document.getElementById("sr_q");
				srQ.innerHTML = sumColumn(5);
			var nrS = document.getElementById("nr_s");
				nrS.innerHTML = "$ "+sumIncome(2,3);
			var srS = document.getElementById("sr_s");
				srS.innerHTML = "$ "+sumIncome(4,5);
			return true;
		}
		function sumColumn(ind){
			var out = 0;
			for(var i=0;i<myGrid.getRowsNum();i++){
				out+= parseFloat(myGrid.cells2(i,ind).getValue())
			}
			return out;
		}
		function sumIncome(indPrice,indQuant){
			var out = 0;
			for(var i=0;i<myGrid.getRowsNum();i++){
				out+= parseFloat(myGrid.cells2(i,indPrice).getValue())*parseFloat(myGrid.cells2(i,indQuant).getValue())
			}
			return out;
		}
	</script>
</head>
<body onload="doOnLoad()">
	<h1>Setting Footer</h1>
	<div id="gridbox" style="width:600px; height:350px;background-color:white;"></div>
	<h3>Setting style for footer:</h3>
	<ul>
		<li>To modify  default style of footer you should redefine "div.gridbox div.ftr td" after dhtmlXGrid.css has been placed on page</li>
		<li>To set explicit style for each cell in footer use the second argument  of <code>attachFooter</code> method.</li>
	</ul>
</body>
</html>

Documentation

Check documentation to learn how to use the components and easily implement them in your applications.