1

I have jqGrid (free jqGrid) that contains 7 columns. And I applied shrinkToFit: false, property to enable scrolling for the grid columns (to fit to mobile device). When I applied the same property to the grid having only one column grid is looking like below image :

enter image description here

How to automatically set grid width according to the number of columns?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Markandeyulu
  • 47
  • 1
  • 7
  • Sorry, but I'm not sure how the grid should looks like. Either you want to fave fixed column widths or you want that some columns will be do resized. Look at the demo http://jsfiddle.net/OlegKi/andm1299/26/. It don't use `shrinkToFit: false` and resize the grid depend on the size of the window (the outer container). It hides the last column in case of small window. Is it what you need? If you need another behavior, please describe it more exactly. – Oleg Feb 19 '16 at 11:24
  • Hi Oleg, I want to use `shrinkToFit:false` as in mobile devices I want to display all columns with horizontal scrollbar if the grid width overflows. When there are only 2 columns then I want the last column width to match the remaining width of the grid. – Markandeyulu Feb 19 '16 at 12:17

1 Answers1

1

You can use setColWidth method (included in free jqGrid) to change the width of the last column dynamically. I don't know which scenario for loading the grid you use. The modification of the demo could be the following: http://jsfiddle.net/OlegKi/andm1299/37/ where

$(window).bind("resize", function () {
    var p = $grid.jqGrid("getGridParam"),
        cm = p.colModel[p.iColByName.ComboDuration];

    $grid.jqGrid("setGridWidth", $grid.closest(".container-fluid").width());
    $grid.jqGrid("setColWidth", "ComboDuration", p.width - p.tblwidth + cm.width);
}).triggerHandler("resize");

The above code first resize the width of grid based on the width of the outer container and then adjust the width of the last column based on the difference between the width of the main grid table and the total width of the grid.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • please help me with this [link](http://stackoverflow.com/questions/43512436/filtering-jqgrid-by-multiple-group-conditions-at-client-side) – Markandeyulu Apr 21 '17 at 04:15