DHTMLX Docs & Samples Explorer

Columns Manipulation

Hiding/Showing Columns

It is possible to define a column as hidden - in such case, it will not be visible for a user, but it will be accessible by API. So it will be possible to take the data from it.

In case of initialization from JS code, the user should write the following:

        grid.setColumnHidden(index,true); // indicate column index and set the state to true to hire the column

In case of initialization from XML, the syntax will be like this:

            <column hidden="true">Dummy</column>

The data can be accessed as data of any other columns:


Data of a hidden column is included in the serialization by default ( this can be controlled by setSerializableColumns() command ) This data is available during dataprocessor calls

Starting from v1.5, the users can enable popup menu for the grid setting visibility for different columns (hide/show them) right on the fly. To do this, the user just needs to include dhtmlxgrid_hmenu.js in page with the grid and call the following command:


Each time when column hidden|shown - onColumnHidden event generated

Split Mode. Frozen Columns

The user can activate split mode to have the grid separated into two parts with independent horizontal scrolling. Using this mode is recommended with some performance optimization technologies (paginal output, smart rendering) taking into account complex script processing in the split mode.

First, the user should include the file dhtmlxgrid_splt.js into the HTML. Then the following code string should be written for split mode activation:

        grid.splitAt(1); // index of the column before which the grid should be split

Note: this method should be called when the grid is initialized. This mode is incompatible with some grid functionality.

Adjusting Column Size

Sometimes it is necessary to adjust column size to content size automatically. This task can be achieved in the following way:


The parameters here is cInd - index of the column in question.

Enabling Columns Resizing

The user should enable/disable resizing of specified columns from script in the following way:

        grid.enableResizing(list); // resizing is enabled for all columns by default

Only one parameter should be indicated: list - list of true|false values.

Enabling Columns Tooltips

Tooltips for specified columns can be specified in the following ways:

        grid.enableTooltips(list); // tooltips are enabled for all columns by default

The parameter that is to be indicated is list - list of true|false values.

Column Id/Index Manipulations

Getting Id through Index and Vice Versa

There are methods allowing to get id/index of the specified column quite easily:

        var colInd = grid.getColIndexById(id); // get column index through its id
        var colId = grid.getColumnId(ind); // get column id through its index

The first method returns index of the column, while the second one - column id.

Setting Column Id

The user can set new id for a certain column with the help of the following method:

        grid.setColumnId(ind, id);

The parameters here are:

  • ind- index of the column;
  • id- new id for the column in question.

Setting Ids for All Columns

There is also the possibility to set new ids for every column in the grid:


The user should specify ids - list of ids separated by a delimiter (default one is ”,”), or empty if using values set earlier.

Getting Column Type

The user can get column type by specifying its id:

        var type = grid.getColTypeById(cId);

The method returns type code of the column in question.

Setting/Getting Column Width

Initial column width can be set either in pixels or in percents in the following way:

        grid.setInitWidths(wp); // list of column width in pixels
        grid.setInitWidthsP(wp); // list of column width in percents

Column width can be easily got in the following way indicating index of the column in question:

        var width = grid.getColWidth(ind); // returns column width in pixels

Getting Number of Columns

Only one line of code is enough for the user to get total number of columns in the grid:

        var cols = grid.getColumnsNum();

Getting Column Status

Column status (shown|hidden) can be got with the help of isColumnHidden() method. The user should indicate this column index:

        var state = grid.isColumnHidden(ind);

The method returns true if the column is hidden, otherwise it will return false.

Setting Column Align

Setting horizontal align of values for the grid columns is quite simple:


The parameter the user should indicate is alStr - list of align values for columns. Default delimiter is ”,”. Possible values are:

  • right;
  • left;
  • center;
  • justify.

The following method is responsible for vertical align of values in grid columns:


Parameter valStr indicates vertical align values list for columns. Default delimiter is ”,”.
Possible values are:

  • baseline;
  • sub;
  • super;
  • top;
  • text-top;
  • middle;
  • bottom;
  • text-bottom.

Setting Column Width

The user can apply the method that sets width of the specified column in pixels.

        grid.setColWidth(ind, value);

The parameters here are:

  • ind - index of the column;
  • value - new width value.

Note: this method will not work with percent-based grid.

Column minimal width can be set through the following method (works only for manual resizing):

        grid.setColumnMinWidth(width, ind);

The parameters here are:

  • width - minimum column width; can be set for one specified column, or as a comma separated list for all columns;
  • ind - index of the column.

Setting Column Color

The user can colorize columns background from script using the following method:

        grid.setColumnColor(clr);  // list of colors for each column should be specified

Controlling Columns Visibility

The user can set the list of visible|hidden grid columns from script like this:


The parameter here is the list of true (visible) or false (hidden) values separated by commas.

Setting Column Excell Type

The user can set/change excell type of a column in the following way:


The parameters the user should indicate:

  • colIndex - index of the column in question;
  • type - type of the excell.

Adding/Removing Column

The user should include dhtmlxgrid_mcol.js file into the page first. Then any column in the grid can be added/removed with script in the following way:

 // can be used after grid's initialization but there should be at least one column in the grid

The parameters for insertColumn() method are:

  • ind - index of the column;
  • header - header content of the column;
  • type - type of the column;
  • width - width of the column;
  • sort - sort type of the column;
  • align - align of the column;
  • valign - vertical align of the column;
  • hidden - hidden state of the column;
  • columnColor - background color of the column.

Moving Column

The following method moves column with the specified index to a new position:


The user should include the following file: dhtmlxgrid_mcol.js , and indicate the following parameters:

  • oldInd - current index of the column;
  • newInd - new index of the column.