在带有Bootstrap的Guriddo jqGrid中,setGridWidth方法的“ shrinktofit”参数设置为“ true”时出现问题

时间:2019-02-01 17:00:06

标签: javascript jquery jqgrid scrollbar shrink

上的jqGrid使用setGridWidth方法与“shrinktofit”参数“真”与自举使用时,导致不必要的水平滚动条显示时的记录数较少(即,不垂直滚动条)。

记录越多,水平滚动条就会消失(即具有垂直滚动条)。 为了演示该问题,我在Loadcomplete上调用了setGridWidth方法

我什至在jsfiddle上复制了这个问题:http://jsfiddle.net/yoabhinav/uqonspmd/

这是在Loadcomplete事件内部注释了setGridWidth方法调用的小提琴,它按预期工作正常:http://jsfiddle.net/yoabhinav/knuj9xet/

$(document).ready(function () {

	const data = { "rows":[{"OrderID":"1","CustomerID":"WILMK","OrderDate":"1996-07-04 00:00:00","Freight":"32.3800","ShipName":"Vins et alcools Chevalier"},{"OrderID":"2","CustomerID":"TRADH","OrderDate":"1996-07-05 00:00:00","Freight":"11.6100","ShipName":"Toms Spezialit\u00e4ten"},{"OrderID":"3","CustomerID":"HANAR","OrderDate":"1996-07-08 00:00:00","Freight":"65.8300","ShipName":"Hanari Carnes"},{"OrderID":"4","CustomerID":"VICTE","OrderDate":"1996-07-08 00:00:00","Freight":"41.3400","ShipName":"Victuailles en stock"},{"OrderID":"5","CustomerID":"SUPRD","OrderDate":"1996-07-09 00:00:00","Freight":"51.3000","ShipName":"Supr\u00eames d\u00e9lices"},{"OrderID":"6","CustomerID":"HANAR","OrderDate":"1996-07-10 00:00:00","Freight":"58.1700","ShipName":"Hanari Carnes"},{"OrderID":"7","CustomerID":"CHOPS","OrderDate":"1996-07-11 00:00:00","Freight":"22.9800","ShipName":"Chop-suey Chinese"},{"OrderID":"8","CustomerID":"RICSU","OrderDate":"1996-07-12 00:00:00","Freight":"148.3300","ShipName":"Richter Supermarkt"},{"OrderID":"9","CustomerID":"WELLI","OrderDate":"1996-07-15 00:00:00","Freight":"13.9700","ShipName":"Wellington Importadora"},{"OrderID":"10","CustomerID":"HILAA","OrderDate":"1996-07-16 00:00:00","Freight":"81.9100","ShipName":"HILARI\u00d3N-Abastos"},{"OrderID":"11","CustomerID":"ERNSH","OrderDate":"1996-07-17 00:00:00","Freight":"140.5100","ShipName":"Ernst Handel"},{"OrderID":"12","CustomerID":"CENTC","OrderDate":"1996-07-18 00:00:00","Freight":"3.2500","ShipName":"Centro comercial Moctezuma"},{"OrderID":"13","CustomerID":"OLDWO","OrderDate":"1996-07-19 00:00:00","Freight":"55.0900","ShipName":"Ottilies K\u00e4seladen"},{"OrderID":"14","CustomerID":"QUEDE","OrderDate":"1996-07-19 00:00:00","Freight":"3.0500","ShipName":"Que Del\u00edcia"},{"OrderID":"15","CustomerID":"RATTC","OrderDate":"1996-07-22 00:00:00","Freight":"48.2900","ShipName":"Rattlesnake Canyon Grocery"},{"OrderID":"16","CustomerID":"ERNSH","OrderDate":"1996-07-23 00:00:00","Freight":"146.0600","ShipName":"Ernst Handel"},{"OrderID":"17","CustomerID":"FOLKO","OrderDate":"1996-07-24 00:00:00","Freight":"3.6700","ShipName":"Folk och f\u00e4 HB"},{"OrderID":"18","CustomerID":"BLONP","OrderDate":"1996-07-25 00:00:00","Freight":"55.2800","ShipName":"Blondel p\u00e8re et fils"},{"OrderID":"19","CustomerID":"WARTH","OrderDate":"1996-07-26 00:00:00","Freight":"25.7300","ShipName":"Wartian Herkku"},{"OrderID":"20","CustomerID":"FRANK","OrderDate":"1996-07-29 00:00:00","Freight":"208.5800","ShipName":"Frankenversand"}]
	}

	$("#jqGrid").jqGrid({
		pager: "#jqGridPager",
		datastr: data,
		datatype: "jsonstring",
		styleUI : 'Bootstrap',
		colModel: [
		  { label: 'OrderID', name: 'OrderID', key: true, width: 75 },
		  { label: 'Customer ID', name: 'CustomerID', width: 150 },
		  { label: 'Order Date', name: 'OrderDate', width: 150 },
		  { label: 'Freight', name: 'Freight', width: 150 },
		  { label:'Ship Name', name: 'ShipName', width: 150 }
		],
		viewrecords: true,
		height: 250,
		rowNum: 5,
		autowidth: true,
		shrinkToFit: true,
		rownumbers: true,
		gridview: false,
		loadComplete: function () {
		  const parent_width = $("#jqGrid").parent().width();
		  $("#jqGrid").jqGrid('setGridWidth', parent_width);
		}
	});
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<link href="http://www.guriddo.net/demo/css/trirand/ui.jqgrid-bootstrap.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://www.guriddo.net/demo/js/trirand/i18n/grid.locale-en.js"></script>
<script src="http://www.guriddo.net/demo/js/trirand/src/jquery.jqGrid.js"></script>

<div>
    <table id="jqGrid"></table>
    <div id="jqGridPager"></div>
</div>

1 个答案:

答案 0 :(得分:1)

此问题已修复,将在下一版本中提供。如果这是一个热门,您可以从GitHub获取固定代码。

更新:如果你只是将响应在jqGrid的设置选项设置为true,可避免在loadComplete使用的代码。我建议您查阅文档here