ExtJS GridPanel根據窗口大小自動變化插件

 

Ext.ns("Ext.grid.plugins");

Ext.grid.plugins.AutoResize = Ext.extend(Ext.util.Observable,{
	init:function(grid){
		grid.applyToMarkup = function(el){
			grid.render(el);
		}
		var containerId = Ext.get(grid.renderTo || grid.applyTo).id;
		if(Ext.isIE){
			Ext.get(containerId).on("resize",function(){
				grid.setWidth.defer(100,grid,[Ext.get(containerId).getWidth()]);
			});
		}else{
			window.onresize = function(){
				grid.setWidth(Ext.get(containerId).getWidth());
			}
		}
	}
});

 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>autoresize</title>
	<link rel="stylesheet" type="text/css" href="http://dev.sencha.com/deploy/dev/resources/css/ext-all.css" />
	<link rel="stylesheet" type="text/css" href="http://dev.sencha.com/deploy/dev/resources/css/xtheme-gray.css" />
 	<script type="text/javascript" src="http://dev.sencha.com/deploy/dev/adapter/ext/ext-base-debug.js"></script>
    <script type="text/javascript" src="http://dev.sencha.com/deploy/dev/ext-all-debug.js"></script>
	<script type="text/javascript" src="http://dev.sencha.com/deploy/dev/src/locale/ext-lang-zh_CN.js"></script>

	<link rel="stylesheet" type="text/css" href="ext-patch.css" />
    <script type="text/javascript" src="AutoResize.js"></script>
    <script type="text/javascript">
		Ext.onReady(function(){
			var data = new Array();
			for(var i=1;i<=100;i++){
				data.push({id:i,name:"name"+i,sex:i%2 == 0?"man":"woman",age:i});
			}
			var grid = new Ext.grid.GridPanel({
				height:600,
				plugins:new Ext.grid.plugins.AutoResize(),
				frame:true,
				title:"Grid",
				//renderTo:"gridPanel",
				applyTo:"gridPanel",
				viewConfig:{
					forceFit:true
				},
				columns:[
					{dataIndex:"id",header:"id",sortable:true},
					{dataIndex:"name",header:"name",sortable:true},
					{dataIndex:"sex",header:"sex",sortable:true},
					{dataIndex:"age",header:"age",sortable:true}
				],
				store:new Ext.data.JsonStore({
					autoLoad:true,
					data:data,
					fields:["id","name","sex","age"]
				})
			});
		});    
    </script>
</head>
<body style="margin:0px;padding:0px;">
	<div id="gridPanel" style="width: 100%;"></div>
</body>
</html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章