Insert/Delete column

You can easily insert/delete columns in your grid using the following methods:


Add Column

Index

Label

Type (code)

Width (px)

In the method above you should specify the following parameters:

  • index - index of column
  • label - content of column
  • typeCode - type of column
  • width - width of column
  • Drop Column

    Drop column by index:
    </> Source
    <!DOCTYPE html>
    <!--pro-->
    <html>
    <head>
    	<title>Insert/Delete column</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("Sales,Book Title,Author,Price,In Store,Shipping,Bestseller,Date of Publication");
    			myGrid.setInitWidths("80,150,120,80,80,80,80,100");
    			myGrid.setColAlign("right,left,left,right,center,left,center,center");
    			myGrid.setColTypes("dyn,ed,ed,price,ch,co,ra,ro");
    			var combobox = myGrid.getCombo(5);
    			combobox.put("1","1 Hour");
    			combobox.put("12","12 Hours");
    			combobox.put("24","24 Hours");
    			combobox.put("48","2 days");
    			combobox.put("168","1 week");
    			combobox.put("pick","pick up");
    			combobox.put("na","na");
    			myGrid.setColSorting("int,str,str,int,str,str,str,str");
    			myGrid.enableMultiselect(true);
    			myGrid.setColumnMinWidth(50,0);
    			myGrid.enableColumnMove(true);
    			myGrid.enableAutoWidth(true);
    			myGrid.enableAutoHeight(true);
    			myGrid.init();
    			myGrid.load("../common/grid_16_rows_columns_manipulations.xml");
    		}
    	</script>
    </head>
    <body onload="doOnLoad()">
    	<h1>Insert/Delete column</h1>
    	<p>You can easily insert/delete columns in your grid using the following methods:</p>
    	<div id="gridbox" style="width:600px;height:350px;background-color:white;"></div>
    	<br>
    	Add Column<br><br>
    	Index <br>
    	<input type="text" id="ind" maxlength="1" size="1" value="0"><br>
    	Label<br>
    	<input type="text" id="lbl" maxlength="50" size="20" value="New Column"><br>
    	Type (code)<br>
    	<input type="text" id="typ" maxlength="3" size="3" value="ed"><br>
    	Width (px)<br>
    	<input type="text" id="wdt" maxlength="3" size="3" value="100"><br>
    	<button onClick="myGrid.insertColumn(document.getElementById('ind').value,document.getElementById('lbl').value,document.getElementById('typ').value,document.getElementById('wdt').value);">Add Column</button>
    	<p>In the method above you should specify the following parameters:</p>
      	<li>index - index of column</li>
    	<li>label - content of column</li>
    	<li>typeCode - type of column</li>
    	<li>width - width of column </li>
    	<p>Drop Column</p>
    	<a href="javascript:void(0)" onClick="myGrid.deleteColumn(document.getElementById('indDrop').value);">Drop</a> column by index: <input type="text" id="indDrop" maxlength="1" size="1" value="0"><br>
    </body>
    </html>
    

    Documentation

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