我正在使用 jqGrid 4.8.2 并设置了固定宽度的网格。但是,当我使用 columnChooser 修改显示的列时,网格的宽度会重新调整为所有列的组合宽度,并且水平滚动消失了。我尝试在“完成” columnChooser 参数中重置宽度,但它不起作用。经过一些调试后,似乎在“完成”完成和对话框窗口关闭之后发生了调整大小。我创建了一个按钮来手动重置宽度,它工作得很好,所以我知道重置宽度可能会发生。我只是不知道使用哪个事件来触发它。
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
}
}
});
}
});