EXT 3. x 상세 한 Ext. grid. GridPanel 사용 (2)

이 편 은 우리 창 이 변 할 때 grid 가 자동 으로 크기 를 조정 할 수 있 도록 grid 를 설명 합 니 다.코드 를 주로 보 세 요. 주석 이 잘 보 여요!
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page pageEncoding="UTF-8"%>
<html>
<head>
<style type="text/css">
	
	html,body{
	margin:0px;
	height:100%;
	}
	
	#content{
	height:100%;
	width:100%;
	}
</style>

</head>
	<body style="height:100%">
	<script type="text/javascript">
	var grid;
	
	var cm;
	
	var ds;
	
	//    
	function renderSex(value) {
		if (value == 'male') {
		return "<span style='color:red;font-weight:bold;'> </span>";
		} else {
		return "<span style='color:green;font-weight:bold;'> </span>";
		}
	}
	
	//    
	function renderDescn(value, cellmeta, record, rowIndex, columnIndex,store){
		var str = (rowIndex+1)+" |"+(columnIndex+1)+" ";
		return str;
	}
	
	//       
	Ext.onReady(function()
		{
	//     
	cm = new Ext.grid.ColumnModel([
		{header:'<font color="blue">  </font>',width: Ext.get("content").getWidth()/4,sortable:true,dataIndex:'id'},//sortable    ,           
		{header:'<font color="blue">  </font>',width: Ext.get("content").getWidth()/4,dataIndex:'sex',renderer:renderSex},
		{header:'<font color="blue">  </font>',width: Ext.get("content").getWidth()/4,dataIndex:'name'},
		{header:'<font color="blue">  </font>',width: Ext.get("content").getWidth()/4,dataIndex:'descn',renderer:renderDescn}
	]);
	
	//       ,Json    
	var data = [
		['1','male','name1','descn1'],
		['2','female','name2','descn2'],
		['3','male','name3','descn3'],
		['4','female','name4','descn4'],
		['5','male','name5','descn5']
	];
	
	//      
	//proxy           ,reader            
	 ds = new Ext.data.Store({
		proxy: new Ext.data.MemoryProxy(data),
		//Ext.data.ArrayReader        ,   cm dataIndex   
		reader: new Ext.data.ArrayReader({}, [
			{name: 'id'},
			{name: 'sex'},
			{name: 'name'},
			{name: 'descn'}
		])
	});
	//  dataStore
	ds.load();
	//  grid  
	grid = new Ext.grid.GridPanel({
		renderTo: 'content',//     div
		//  div    ,           ,    grid        grid   
		width: Ext.get("content").getWidth(),
		height: Ext.get("content").getHeight(), 
		//  ds cm
		store: ds,
		cm: cm
	});
	});
	//           
	window.onresize=function(){
		grid.destroy();
		cm = new Ext.grid.ColumnModel([
		//        ,                    ,      grid      
			{header:'<font color="blue">  </font>',width: Ext.get("content").getWidth()/4,sortable:true,dataIndex:'id'},
			{header:'<font color="blue">  </font>',width: Ext.get("content").getWidth()/4,dataIndex:'sex',renderer:renderSex},
			{header:'<font color="blue">  </font>',width: Ext.get("content").getWidth()/4,dataIndex:'name'},
			{header:'<font color="blue">  </font>',width: Ext.get("content").getWidth()/4,dataIndex:'descn',renderer:renderDescn}
		]);
        grid = new Ext.grid.GridPanel({
			width: Ext.get("content").getWidth(),
			height: Ext.get("content").getHeight(), 
			store: ds,
			cm: cm
		});
		grid.render(Ext.get("content"));
	};
    </script>
    
<div id="content">
<div>

	</body>
</html>

좋은 웹페이지 즐겨찾기