我正在尝试使用 jqgrid 创建一个最初没有数据但具有固定大小的网格,其中列的总宽度大于网格宽度,因此用户只能滚动浏览标题。用户将单击一个按钮,该按钮会将数据填充到网格中。这听起来可能类似于已经回答的问题jqGrid 垂直滚动条
但是,在这种情况下,数据已经存在。我最初没有数据,希望网格有滚动条。我注意到在填充数据之前,不会创建具有类 .ui-jqgrid-bdiv 的 div。
这是 jqgrid 中的错误吗?有什么解决方法吗?
这是小提琴http://jsfiddle.net/yNw3C/2630/
这是代码:
javascript
$(document).ready(function () {
$("#results").jqGrid({
datatype: "local",
height: 150,
scroll:true,
width:300,
shrinkToFit:false,
colNames: ['Inv No', 'Date', 'Client', 'Amount', 'Tax', 'Total', 'Notes'],
colModel: [
{ name: 'id', index: 'id', width: 160, sorttype: "int" },
{ name: 'invdate', index: 'invdate', width: 90, sorttype: "date" },
{ name: 'name', index: 'name', width: 100 },
{ name: 'amount', index: 'amount', width: 80, align: "right", sorttype: "float" },
{ name: 'tax', index: 'tax', width: 180, align: "right", sorttype: "float" },
{ name: 'total', index: 'total', width: 280, align: "right", sorttype: "float" },
{ name: 'note', index: 'note', width: 150, sortable: false }
],
});
var mydata = [
{ id: "1", invdate: "2007-10-01", name: "test", note: "note", amount: "200.00", tax: "10.00", total: "210.00" },
{ id: "2", invdate: "2007-10-02", name: "test2", note: "note2", amount: "300.00", tax: "20.00", total: "320.00" },
{ id: "3", invdate: "2007-09-01", name: "test3", note: "note3", amount: "400.00", tax: "30.00", total: "430.00" },
{ id: "4", invdate: "2007-10-04", name: "test", note: "note", amount: "200.00", tax: "10.00", total: "210.00" },
{ id: "5", invdate: "2007-10-05", name: "test2", note: "note2", amount: "300.00", tax: "20.00", total: "320.00" },
{ id: "6", invdate: "2007-09-06", name: "test3", note: "note3", amount: "400.00", tax: "30.00", total: "430.00" },
{ id: "7", invdate: "2007-10-04", name: "test", note: "note", amount: "200.00", tax: "10.00", total: "210.00" },
{ id: "8", invdate: "2007-10-03", name: "test2", note: "note2", amount: "300.00", tax: "20.00", total: "320.00" },
{ id: "9", invdate: "2007-09-01", name: "test3", note: "note3", amount: "400.00", tax: "30.00", total: "430.00" }
];
//if you uncomment this, the scrollbars would appear
/*for (var i = 0; i <= mydata.length; i++)
$("#results").jqGrid('addRowData', i + 1, mydata[i]);*/
});
html
<div>
<table id="results"></table>
</div>
编辑:为了更清楚,在上面的例子中,我想水平滚动标题。填充数据后,标题在垂直滚动时应保持静态,并与数据一起水平滚动。
谢谢!