Width of the column to autofit


I’m making use of grid. I’ve set the


and to auto resize the grid i’ve made use of

function onLoadingEndFunc(){

var count = mygrid.getColumnCount();

for(var i = 0; i < count; i++)






mygrid.loadXMLString(sXML, onLoadingEndFunc);

Grid without using the onLoadingEndFunc ,

|New | One | Two | Three | Four | Five | Six | Seven |Eight | --> Considering the size of column as 100

Grid After Using onLoadingEndFunc with 6 columns,

|New | One | Two | Three | Four | Five |

Grid After Using onLoadingEndFunc with 3 columns,

| NEw |One | Two |

here by using the above code the grid size is always maintained to 900 even though the number

of columns are 3/4/5…

In this if the number of columns are more, then the columns are generated with proper widths.

If the number of columns is less than three then the widths of the columns become very large.

The width of the columns here are based on the number of columns present. i don’t want the size

of the grid to be always 900. I just want the column widths to get expanded to the length of

the text.

I’ve tried making use of ‘enableMultiLine’, but i’m also making use of ‘enableSmartRendering’ as they are mutually exclusive i couldn’t make use of the ‘enableMultiLine’ option.

How can i acheive the above mentioned property? Kindly suggest me on how to proceed?

here by using the above code the grid size is always maintained to 900 even though the number 
of columns are 3/4/5
If you have
The grid must autosize its width , so it will not be greater than 900px in width, but it may be lesser than such value.
Please check attached sample - it uses the same approach, and grid has lesser width with lesser count of columns.

Please be sure that you are not using auto-size columns ( size = * ) during grid initialization - such columns will not work correctly with adjustColumnSize
1214557791.zip (84.7 KB)

Thanks for the reply,

But with the code

mygrid.enableAutoWidth(true, 900); //With column size as 100

i’m unable to get the value in the header autowrapped. To get the value in the header auto wrapped i’m making use of the “onLoadingEndFunc”.

Here when the number of column are less the function “onLoadingEndFunc” is causing the grid to fit to 900.

Can you please suggest me on how to overcome the problem?

The adjustColumn functionality calculate width of columns including header row. There is no way to adjust grid column widht only by width of data part of column.
You can modify dhtmlxgrid.js in next way

       adjustColumnSize:function(cInd, complex){
        var m = 0;
        this._setColumnSizeR(cInd, 20);
    // you can comment next loop, it will disable part of code, which calculate width of headers
    /*    for (var j = 1; j < this.hdr.rows.length; j++){

Thanks for the sppedy reply,

Do you have any plans of including this change in any of the future builds? If yes when can we expect?

Currently we have not plans to change behavior of adjustColumn functionality in such way.
The existing solution, which includes height of data and header in calculation, works as expected in most situation.