DHTMLX Docs & Samples Explorer

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.

THIS PAGE CONTAINS SAMPLE FUNCTIONALITY OF PROFESSIONAL EDITION FOR DEMONSTRATION PURPOSE ONLY.
UNAUTHORIZED USE IS PROHIBITED. PLEASE CONTACT SALES@DHTMLX.COM TO OBTAIN A LEGAL COPY OF PROFESSIONAL EDITION.
Source
<link rel="STYLESHEET" type="text/css" href="../../codebase/dhtmlxgrid.css">
<link rel="stylesheet" type="text/css" href="../../codebase/skins/dhtmlxgrid_dhx_skyblue.css">
<script  src="../../codebase/dhtmlxcommon.js"></script>
<script  src="../../codebase/dhtmlxgrid.js"></script>
<script  src="../../codebase/ext/dhtmlxgrid_mcol.js"></script>
<script  src="../../codebase/dhtmlxgridcell.js"></script>
 
 
 
<div id="gridbox" style="width:600px;height:270px;background-color:white;"></div>
 
 
 
<script>
mygrid = new dhtmlXGridObject('gridbox');
mygrid.setImagePath("../../codebase/imgs/");
mygrid.setHeader("Sales,Book Title,Author,Price,In Store,Shipping,Bestseller,Date of Publication");
mygrid.setInitWidths("50,150,120,80,80,80,80,200");
mygrid.setColAlign("right,left,left,right,center,left,center,center");
mygrid.setColTypes("dyn,ed,ed,price,ch,co,ra,ro");
mygrid.getCombo(5).put(2, 2);
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.init();
mygrid.setSkin("dhx_skyblue");
mygrid.loadXML("../common/grid_16_rows_columns_manipulations.xml");
</script>