對此問題一直耿耿於懷,後來終於想出了一個辦法,還真的可行,但就是感覺有點蹩腳。
一般我們都通過render到指定id的層上來展現grid,雖然不能讓grid寬高自適應,但層還是可以的。
如我們這裏要用到的層是<div id="orgGrid"></div>。我們可以在這個層上設置高寬。
如<div id="orgGrid" style="width:100%;height:250px"></div>。
則在初始化grid的時候讓其寬高與orgGrid寬高相同即可,並在頁面resize時重新計算器寬度即可(一般高度固定還是比較好)。
js代碼如下:
//..前面若干行代碼省略,如ds/colmodel等
var orgGrid=Ext.get("orgGrid"); //展示grid的容器
var grid = new Ext.grid.GridPanel({
title:"人員管理",
ds: ds, //數據源
cm: colModel, //列模式
sm:selMode, //選擇模式
width:orgGrid.getComputedWidth(),
height:orgGrid.getComputedHeight(),
autoExpandColumn:"memory", //自動擴展寬度的列
autoScroll:true,
loadMask:{msg:"數據加載中,請稍等"}
});
ds.load();
grid.render(orgGrid); //把grid鋪到id爲grid的容器中
window.onresize=function(){
grid.setWidth(0);
grid.setWidth(orgGrid.getComputedWidth());
};
這樣不論頁面寬度怎麼變化grid都會自適應頁面容器了。
var orgGrid=Ext.get("orgGrid"); //展示grid的容器
var grid = new Ext.grid.GridPanel({
title:"人員管理",
ds: ds, //數據源
cm: colModel, //列模式
sm:selMode, //選擇模式
width:orgGrid.getComputedWidth(),
height:orgGrid.getComputedHeight(),
autoExpandColumn:"memory", //自動擴展寬度的列
autoScroll:true,
loadMask:{msg:"數據加載中,請稍等"}
});
ds.load();
grid.render(orgGrid); //把grid鋪到id爲grid的容器中
window.onresize=function(){
grid.setWidth(0);
grid.setWidth(orgGrid.getComputedWidth());
};