Ext.onReady(function(){
//数组
var data = [[1,'张三',24],[2,'李四',30],[3,'王五',22]];
//创建记录类型Person,mapping值为字段值对应数组中的索引位置
var Person = Ext.data.Record.create([
{name: 'personId',mapping: 0},
{name: 'personName',mapping: 1},
{name: 'personAge',mapping: 2}
])
//创建每一列的header
var cm = new Ext.grid.ColumnModel([
{header : 'id',width : 50 , dataIndex: 'personId' ,sortable : true},
{header : '姓名',width : 60 ,dataIndex: 'personName' ,sortable : true},
{header : '年龄',width : 60 ,dataIndex: 'personAge',sortable : true}
]);
//grid面板
var grid = new Ext.grid.GridPanel({
title : '简单grid示例',
applyTo: 'grid',
width : 250,
height : 150,
frame : true,
store : new Ext.data.Store({
reader : new Ext.data.ArrayReader({},Person),
data : data
}),
cm : cm
});
});
index.html
<html>
<head>
<title></title>
<script type="text/javascript" src="extjs/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="extjs/ext-all.js"></script>
<link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css">
<script type="text/javascript" src="js/grid.js"></script>
</head>
<body>
<div id="grid"></div>
</body>
</html>