javascriptdynamicdatagriddojodojox.grid.datagrid

Set dojox.grid.datagrid header column width dynamically


I am able to get the particular column's width using below code. How to set back this width to textbox value.

dojo.forEach(dijit.byId(tableID).layout.cells, function(cell,idx){
                if(cell.field == id){
                    headerWidth = cell.width;
                    alert(headerWidth);
                }
            });

Solution

  • There is a method called setCellWidth() (you can read about it in the API Documentation) which you can use to change the width of the cells.

    The only step you then need to complete is to update the column (so that the changes become visible). This step can be completed with cell.view.update();.

    Be aware: updating the complete grid with grid.update() or grid.sizeChange() is not enough because it will only update the column headers. (That's something I noticed.)

    So in your forEach loop you would do something like:

    grid.setCellWidth(idx, "200px");
    cell.view.update();
    

    I also made a working JSFiddle which you can view here.