Move column

You have two ways of moving columns within the grid:

Firstly, you are allowed to move column using drag-n-drop functiality.

enableColumnMove method enables drag-n-drop operations:

Otherwise, you can move column with script:

Move column before column

In the method above you should specify indexes of old and new columns.

</> Source
<!DOCTYPE html>
<!--pro-->
<html>
<head>
	<title>Move 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.setColumnColor("white,#d5f1ff,#d5f1ff");
			myGrid.enableMultiselect(true);
			myGrid.setColumnMinWidth(50,0);
			myGrid.enableColumnMove(true);
			myGrid.attachEvent("onBeforeCMove",function(a,b){
				return confirm("Allow move column "+a+" to position "+b);
			});
			myGrid.enableAutoWidth(true);
			myGrid.enableAutoHeight(true);
			myGrid.init();
			myGrid.load("../common/grid_16_rows_columns_manipulations.xml");
		}
	</script>
</head>
<body onload="doOnLoad()">
	<h1>Move column</h1>
	<p>You have two ways of moving columns within the grid:</p>
	<div id="gridbox" style="width:600px;height:350px;background-color:white;"></div>
	<p>Firstly, you are allowed to move column using drag-n-drop functiality.</p>
	<p>enableColumnMove method enables drag-n-drop operations:</p>
	<p>Otherwise, you can move column with script:</p>
	<p>
		<a href="javascript:void(0)" onClick="myGrid.moveColumn(document.getElementById('sInd').value,document.getElementById('tInd').value)">Move</a>
		column
		<select id="sInd">
			<option value="0">0
			<option value="1">1
			<option value="2">2
			<option value="3">3
			<option value="4">4
			<option value="5">5
			<option value="6">6
			<option value="7">7
		</select>
		before column
		<select id="tInd">
			<option value="0">0
			<option value="1">1
			<option value="2">2
			<option value="3">3
			<option value="4">4
			<option value="5">5
			<option value="6">6
			<option value="7">7
		</select>
	</p>
	<p>In the method above you should specify indexes of old and new columns.</p>
</body>
</html>

Documentation

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