Rectangle 27 0

Short answer on your question could be: jqGrid provide no method which allows to change column width after grid have created. In such cases I remind well known aphorism of Kozma Prutkov: "Who prevents you invent gunpowder waterproof?". It means about the following: if something not exists it can be still invented. So I wrote such method based on the solution suggested in the answer where I suggested to call internal method dragEnd to resize grid's column.

The demo demonstrate the usage of new method. The demo allows to choose some column of the grid and then to change the width to new value which you specify:

The code of new method you can find below

    setColWidth: function (iCol, newWidth, adjustGridWidth) {
        return this.each(function () {
            var $self = $(this), grid = this.grid, p = this.p, colName, colModel = p.colModel, i, nCol;
            if (typeof iCol === "string") {
                // the first parametrer is column name instead of index
                colName = iCol;
                for (i = 0, nCol = colModel.length; i < nCol; i++) {
                    if (colModel[i].name === colName) {
                        iCol = i;
                if (i >= nCol) {
                    return; // error: non-existing column name specified as the first parameter
            } else if (typeof iCol !== "number") {
                return; // error: wrong parameters
            grid.resizing = { idx: iCol };
            grid.headers[iCol].newWidth = newWidth;
            grid.newWidth = p.tblwidth + newWidth - grid.headers[iCol].width;
            grid.dragEnd();   // adjust column width
            if (adjustGridWidth !== false) {
                $self.jqGrid("setGridWidth", grid.newWidth, false); // adjust grid width too

You can include the method in your project and then use setColWidth method. The first parameter of the method is either the column index or the column name. The second parameter is a number which specify new value of the width on the column. The third parameter is optional. If it's not specified then the width of the grid will be automatically adjusted corresponds to the changing of the column width. So the grid will have no scroll bars if it hasn't before changing the column width. If you want to hold the original grid width you should specify false as the third parameter of setColWidth method.

UPDATED: The latest (updated) version of setColWidth can be downloaded from github. The new free version of jqGrid which is developing currently here includes the method as in the basis module of jqGrid. So if you use jquery.jqGrid.min.js, and jquery.jqGrid.src.js from here then you don't need include jQuery.jqGrid.autoWidthColumns.js with setColWidth as plugin.

UPDATED 2: I modified the above code to corresponds the latest version of setColWidth which I published to github.

Thanks for the cool demo. See my "update" on what I ended up doing. Any idea on how to calculate the exact width in pixels that I should return?

@dreamfly: You are welcome! I find "update" a little strange. First of all it's new question (the original was "How to adjust the column width of jqGrid AFTER the data is loaded?"). Seconds I don't recommend to change source code of jqGrid if it's really required. Instead of that you can use loadComplete or beforeProcessing. Now about your main question: I think that you can wrap cell content inside of <span>...</span>. After that you can use jQuery.width to compute the exact width in pixel of every <span> and so of every text in the cell. Finally you can use setColWidth.

I am well aware of the pitfall of changing the source code. This is just a proof of concept on how difficult it is to implement this in my opinion a rather simple but very useful feature. especially the simple HTML table does that natively. Of course efficiency was also achieved without re-processing the data.

jquery - How to adjust the column width of jqgrid AFTER the data is lo...

jquery html jqgrid width