<link rel="stylesheet" type="text/css" href="../../../resources/css/ext-all.css" />
<script type="text/javascript" src="../../adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../../ext-all.js"></script>
</head>
<body>
<div id="hello"></div>
</body>
</html>
<script language="javascript" type="text/javascript">
//此函数来自网上,出处不详,非本人原创
Ext.data.Store.prototype.applySort = function() {
if (this.sortInfo && !this.remoteSort) {
var s = this.sortInfo, f = s.field;
var st = this.fields.get(f).sortType;
var fn = function(r1, r2) {
var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
if (typeof(v1) == "string") {
return v1.localeCompare(v2);
}
return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
};
this.data.sort(s.direction, fn);
if(this.snapshot && this.snapshot != this.data) {
this.snapshot.sort(s.direction, fn);
}
}
};
function init(){
var cm = new Ext.grid.ColumnModel([
{header:"id",dataIndex:"id",sortable:true,width:20},
{header:"name",dataIndex:"name",sortable:true,width:60},
{header:"desc",dataIndex:"desc",width:100}
]);
var datas = [
[1,'艾华','好人'],
[2,'宝花','美女'],
[3,'美眉','也是美女'],
[4,'帅哥','不错'],
[5,'猪八戒','好色']
];
var store = new Ext.data.Store({
proxy:new Ext.data.MemoryProxy(datas),
reader:new Ext.data.ArrayReader({},
[
{name:"id"},
{name:"name"},
{name:"desc"}
]),
sortInfo:{field:'name',direction:'ASC'}
});
store.load();
var grid = new Ext.grid.GridPanel({
autoHeight:true,
renderTo:'hello',
store:store,
cm:cm,
});
}
Ext.onReady(init);
</script>