I am using jqGrid with the autowidth
option set to true
.
According to the documentation:
When set to true, the grid width is recalculated automatically to the width of the parent element. This is done only initially when the grid is created. In order to resize the grid when the parent element changes width you should apply custom code and use a setGridWidth method for this purpose
This makes the grid occupy all the width available in the parent element. Another effect of this property is that every column shrinks to fit the width available.
This works very well. However, I have one page where don't want the columns to shrink to fit the grid width, but they should occupy the space that I set within the colModel
for them.
How can I achieve this?
In this step, we are going to add jqGrid Script and CSS reference to index view. This script is added to project when we add jqGrid Grid from NuGet package. After adding Scripts and Css next we need to add table element for reserve the place where the grid should be created.
You can set the new width of the column using two methods – setColProp and setGridWidth. This solution works, except that I needed to use "widthOrg" instead of "width" in the call to 'setColProp'.
In a nutshell, colNames defines the names of your jqGrid columns on the page, and colModel specifies options for each column (name in the dataset, width, etc). The documentation has more information: colModel Array which describes the parameters of the columns. This is the most important part of the grid.
Solution: shrinkToFit: false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With