1

I try to change the width of a Column inside an ajax request:

 $.ajax({
    type: "POST",
    url: "Main.aspx/GetColWidth",
    data: {},
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (a) {
        $("#UsersGrid").jqGrid("setColProp", "colname", {width: 100});
    }
});

If I call the getGridParam right after I call setColProp, I can see the new width, but nothing changes on the table. The Column has its old width.

user576914
  • 199
  • 1
  • 8
  • 22

1 Answers1

3

jqGrid don't provide any method which can be used to change the width after the grid is created. The method setColProp just applies the changes on the corresponding item of colModel, but it *don't applies the changes on the grid.

Nevertheless I wrote setColWidth which allows to change the column width. You can download the latest version of setColWidth from github, include jQuery.jqGrid.setColWidth.js file after jquery.jqGrid.min.js. After that you can use

$("#UsersGrid").jqGrid("setColWidth", "colname", newColumnWidth);

or

$("#UsersGrid").jqGrid("setColWidth", "colname", newColumnWidth, false);

which don't adjust the width of the grid additionally after changing the size of the column. The first call (without false) is especially suitable in case of usage shrinkToFit: true option.

You can find the demo which usessetColWidth in the answer for which I initially developed the setColWidth method.

UPDATE: setColWidth is the part of free jqGrid. Thus one need just update to the latest version of jqGrid to be able to use setColWidth method.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Your code works perfect. Thanks Oleg. Now i need to figure out myself why if I use the code inside ajax doesn't change the widths – user576914 Jan 15 '15 at 09:48