52,797
社区成员
发帖
与我相关
我的任务
分享
Ext.onReady(function (){
var cm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),
{header:'序号',dataIndex:'id',sortable:true},
{header:'姓名',dataIndex:'name'},
{header:'Email',dataIndex:'email'},
{header:'性别',dataIndex:'sex',renderer:formatSex},
{header:'年龄',dataIndex:'age'}]);
function formatSex(value) {
return value == '0'
? "<span style='color:red;'>男</span>"
: "<span style='color:green;'>女</span>";
}
var data = {total:11,
root:[{id:'11',name:'zhangshenghong1',email:'zsh@sina.com',sex:'1',age:'11'},
{id:'12',name:'zhangshenghong2',email:'zsh@sina.com',sex:'0',age:'12'},
{id:'13',name:'zhangshenghong3',email:'zsh@sina.com',sex:'1',age:'13'},
{id:'14',name:'zhangshenghong4',email:'zsh@sina.com',sex:'0',age:'14'},
{id:'15',name:'zhangshenghong5',email:'zsh@sina.com',sex:'1',age:'13'},
{id:'16',name:'zhangshenghong6',email:'zsh@sina.com',sex:'0',age:'14'},
{id:'17',name:'zhangshenghong7',email:'zsh@sina.com',sex:'1',age:'13'},
{id:'18',name:'zhangshenghong8',email:'zsh@sina.com',sex:'0',age:'14'},
{id:'19',name:'zhangshenghong9',email:'zsh@sina.com',sex:'1',age:'13'},
{id:'20',name:'zhangshenghong10',email:'zsh@sina.com',sex:'0',age:'14'},
{id:'21',name:'zhangshenghong11',email:'zsh@sina.com',sex:'1',age:'15'}]};
var store = new Ext.data.Store({
proxy:new Ext.data.MemoryProxy(data),
reader:new Ext.data.JsonReader({
id:'id',
totalProperty:'total',
root:'root'
},[
{name:'id'},
{name:'name'},
{name:'email'},
{name:'sex'},
{name:'age'}
])
});
var grid = new Ext.grid.GridPanel({
cm:cm,
store:store,
title:'grid列表显示示例',
width:600,
height:350,
loadMask:true,
viewConfig:{sortAscText:'正序',sortDescText:'逆序',columnsText:'列'},
tbar : new Ext.PagingToolbar({
pageSize : 5,
store : store,
displayInfo : true,
displayMsg : '显示第 {0} 条到第 {1} 条记录,共 {2} 条记录.',
emptyMsg : '没有记录'
}),
bbar : new Ext.PagingToolbar({
pageSize : 5,
store : store,
displayInfo : true,
displayMsg : '显示第 {0} 条到第 {1} 条记录,共 {2} 条记录.',
emptyMsg : '没有记录'
})
});
grid.render(Ext.getBody());
store.load({params:{start:0, limit:5}});
});