調整瀏覽器大小時是否調整jqGrid的大?。?/h1>
3 回答

TA貢獻1810條經驗 獲得超4個贊
現在已經在生產環境中使用了一段時間,沒有任何抱怨(可能需要一些調整才能在您的網站上看起來正確。例如,減去邊欄的寬度,等等)
$(window).bind('resize', function() {
$("#jqgrid").setGridWidth($(window).width());
}).trigger('resize');

TA貢獻1772條經驗 獲得超6個贊
作為后續措施:
由于不可靠,本文中顯示的先前代碼最終被放棄了。我現在按照jqGrid文檔的建議,使用以下API函數調整網格大?。?/p>
jQuery("#targetGrid").setGridWidth(width);
為了進行實際的大小調整,將實現以下邏輯的函數綁定到窗口的resize事件:
使用其父級的clientWidth和其offsetWidth屬性(如果不可用)計算網格的寬度。
執行健全性檢查,以確保寬度變化超過x個像素(以解決某些特定于應用程序的問題)
最后,使用setGridWidth()更改網格的寬度
這是處理大小調整的示例代碼:
jQuery(window).bind('resize', function() {
// Get width of parent container
var width = jQuery(targetContainer).attr('clientWidth');
if (width == null || width < 1){
// For IE, revert to offsetWidth if necessary
width = jQuery(targetContainer).attr('offsetWidth');
}
width = width - 2; // Fudge factor to prevent horizontal scrollbars
if (width > 0 &&
// Only resize if new width exceeds a minimal threshold
// Fixes IE issue with in-place resizing when mousing-over frame bars
Math.abs(width - jQuery(targetGrid).width()) > 5)
{
jQuery(targetGrid).setGridWidth(width);
}
}).trigger('resize');
和示例標記:
<div id="grid_container">
<table id="grid"></table>
<div id="grid_pgr"></div>
</div>
添加回答
舉報