I am using jqGrid to display the data. I am using hidecol/showcol to hide/show columns in the jqGrid. ShrinkToFit is true.
First I am hiding the column using hideCol. When user select one option I am displaying the hidden column using showCol method. The problem is each time when I call showCol it is reducing the width of that column.
Sample Code:
var mydata = [{name1:"abcdef",name2:"abcdef",name3:"abcdef"},
{name1:"abcdef",name2:"abcdef",name3:"abcdef"},
{name1:"abcdef",name2:"abcdef",name3:"abcdef"},
{name1:"abcdef",name2:"abcdef",name3:"abcdef"},
{name1:"abcdef",name2:"abcdef",name3:"abcdef"},
{name1:"abcdef",name2:"abcdef",name3:"abcdef"}];
jQuery("#list2").jqGrid({ data: mydata,
datatype: 'local',
height: 300,
rowNum: 30,
rowList: [10,20,30],
colNames:['Name1','Name2', 'Name3'],
colModel:[ {name:'name1',index:'name1', width:250},
{name:'name2',index:'name2', width:225},
{name:'name3',index:'name3', width:250}],
pager: '#pager2',
viewrecords: true,
sortorder: "desc",
hidegrid: false
}).navGrid('#pager2',{edit:false,add:false,del:false,search:true},
{},{},{},{});}
jQuery("#list2").jqGrid().showCol("name1"); //show col
jQuery("#list2").jqGrid().hideCol("name1"); //hide col
Best Answer
It seems the same problem which I has recently. I described the bug with my suggestions to fix it in the trirand forum here. The problem is already fixed in the code on the github.
I recommend you to look additionally on another my suggestion which improved performance of
showCol
andhideCol
methods. The suggestions are included in the github code of jqGrid.You can make the same changes in the
jquery.jqGrid.src.js
.