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

Problem in setGridWidth method with ‘shrinktofit’ parameter set to’ true’ in Guriddo jqGrid with Bootstrap

在与 Bootstrap 一起使用时,在 jqGrid 上使用带有 'shrinktofit' 参数 'true' 的 setGridWidth 方法会导致在记录数较少时出现不必要的水平滚动条(即没有垂直滚动条)。

记录一多,水平滚动条就消失(即垂直滚动条)。 为了演示这个问题,我在 Loadcomplete

上调用了 setGridWidth 方法

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

这是一个 fiddle 在 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>

此问题已修复,将在下一版本中提供。如果这对您来说是一个阻碍,您可以从 GitHub 获得固定代码。

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