我想用jqgrid创建一个最初没有数据但具有固定大小的网格,其中列宽总大于网格宽度,以便用户只能滚动通过标题。用户将点击一个按钮,将数据填入网格中。这听起来可能类似于已经回答的问题jqGrid vertical scrollbar没有数据填充的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>
编辑: 更清楚,在上述的例子,我想横向滚动h标题。填充数据时,标题在垂直滚动时应保持静态,并与数据一起水平滚动。
谢谢!
与mydata相比,列声明不同。 – pudaykiran 2014-02-19 13:00:20