ExtJS组件 - store ①

Ext.onReady(function(){
	
	Ext.BLANK_IMAGE_URL = '../ext-2.2/resources/images/default/s.gif';
	
    var cm = new Ext.grid.ColumnModel([
        {header:'编号',dataIndex:'id',sortable:true},
        {header:'名称',dataIndex:'name',width:80},
        {id:'descn',header:'描述',dataIndex:'descn'},
        {header:'日期',dataIndex:'date', renderer: Ext.util.Format.dateRenderer('Y-m-d')}
    ]);

    var data = [
        ['1','name1','descn1','1970-01-15T02:58:04'],
        ['2','name2','descn2','1970-01-15T02:58:04'],
        ['3','name3','descn3','1970-01-15T02:58:04'],
        ['4','name4','descn4','1970-01-15T02:58:04'],
        ['5','name5','descn5','1970-01-15T02:58:04']
    ];

    var store = new Ext.data.Store({
        proxy: new Ext.data.MemoryProxy(data),
        reader: new Ext.data.ArrayReader(
	        {},
	        [
	            {name: 'id'},
	            {name: 'name'},
	            {name: 'descn'},
	            {name: 'date', type:'date',dateFormat: 'Y-m-dTH:i:s'}
	        ])
//	        ,sortInfo:{field:'id',direction: 'DESC'}//指定排序字段
    });
    store.load();

    var grid = new Ext.grid.GridPanel({
        autoHeight: true,
        renderTo: 'grid',
        store: store,
        cm: cm,
//        autoExpandColumn:'descn'//指定某个列之id,grid就会在这一列自动扩展宽度,以填满空白的位置
        stripeRows: true, // 隔行换色
        viewConfig: {
            forceFit: true
        } //强制填充
        ,animCollapse:true
    });
    
   /** // 遍历 store
    for(var i=0;i<store.getCount();i++){
    	alert('store for:'+store.getAt(i).get('name'));
    }
    store.each(function(record){
    	alert('store.each:'+record.get('name'));
    });
//   指定获取范围
    var record = store.getRange(0,2);
    for(var i=0;i<record.length;i++){
    	alert('指定获取范围:'+record[i].get('name'));
    }
    **/
});





你可能感兴趣的:(ext)