I am using jqGrid 4.8.2 and have set up my grid with a fixed width. But, when I modify the displayed columns using columnChooser, the width of the grid is readjusted to the combined width of all columns and the horizontal scroll is gone. I've tried resetting the width within the 'done' columnChooser param but it does not work. After some debugging it seems the resizing happens after 'done' is completed and after the dialog window is closed. I created a button to reset the width manually and that works just fine so I know resetting the width can happen. I just don't know which event to use to trigger it.
var defaultColModel =
[
{name:'REQUESTEDDATE'
,index:'r.requestedDate'
,label:'Request Date'
,sorttype:"date"
,template: "date"
,search:true
,width:100
,hidden:false
},
{name:'VENDORNAME'
,index:'v.companyName'
,label:'Vendor'
,search:true
,stype:'text'
,width:150
,formatter:'showlink'
,formatoptions:{baseLinkUrl:'<cfoutput>#application.rootpath#</cfoutput>', addParam: '&page=dsp_request#vendorT', idName:'REQUESTID'}
,hidden:false
},
{name:'VENDORID'
,index:'r.vendorID'
,label:'Vendor ID'
,search:true
,stype:'text'
,width:100
,hidden:true
},
{name:'VENDORCONTACT'
,index:'vendorContact'
,label:'Vendor Contact'
,stype:'text'
,search:true
,width:100
,hidden:true
} // there are many more cols. Just showing a few to illustrate how they are defined.
]
var myGrid = jQuery("#contract_grid").jqGrid({
url: 'cfc/com_ajxRequestNew.cfc?method=getReqJSON&returnformat=json',
datatype: 'json',
postData: {filters: myFilters},
mtype: 'POST',
search: true,
colModel: defaultColModel,
gridview: false, //added for IE
altRows: true,
emptyrecords: 'NO DATA FOUND',
height: 400,
width: 1200,
sortname: lastSortName,
sortorder: lastSortOrder,
page: lastPage,
pager: jQuery('#report_pager'),
rowNum: lastRowNum,
rowList: [10,20,50,100],
viewrecords: true,
clearSearch: false,
caption: "Contracts Dashboard",
sortable: true,
shrinkToFit: false,
excel: true,
ajaxSelectOptions: {type: "GET"},
gridComplete: function() {//removed code for simplicity}
});
jQuery("#contract_grid").navGrid('#report_pager',{
edit:false,
add:false,
del:false,
search:false,
refresh:false
}).navButtonAdd("#report_pager",{
caption: "Columns",
buttonicon: "ui-icon-calculator",
title: "Select and Reorder Columns",
jqModal: true,
onClickButton: function(e){
$('#contract_grid').jqGrid('columnChooser', {
dialog_opts: {
modal: true,
minWidth: 470,
show: 'blind',
hide: 'explode'
},
done : function (perm) {
if (perm) {
// "OK" button are clicked
$('#contract_grid').jqGrid("remapColumns", perm, true);
// **UPDATED WORKING CODE**get the width set for the grid
var gwdth = $('#contract_grid').jqGrid("getGridParam","width");
// set the tblwidth so the grid does not get resized
$('#contract_grid').setGridParam({tblwidth:gwdth});
} else {
// we can do some action in case of "Cancel" button clicked
}
}
});
}
});