我想用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