日期:2014-05-16 浏览次数:20840 次
Ext.onReady(function(){ var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', { clicksToMoveEditor: 1, autoCancel: false }); Ext.create('Ext.data.Store', { storeId:'findEvertsStore', fields: ['id', 'calendar','title', 'start','end', 'loc','notes', 'url','ad', 'rem', 'n'], proxy: { type: 'ajax', url: 'findEverts.action', reader: { type: 'json', root: 'everts' } }, autoLoad: true }); var states = Ext.create('Ext.data.Store', { fields:['id','title'], proxy: { type: 'ajax', url: 'findCalendars.action', reader: { type: 'json', root: 'calendars' } }, autoLoad: true }); var grid = Ext.create('Ext.grid.Panel', { title: 'Simpsons', store: Ext.data.StoreManager.lookup('findEvertsStore'), columns: [ { header: 'id', dataIndex: 'id' }, { header: 'calendar', dataIndex: 'calendar', renderer: function(value){ if(value != null){ return value.title; } }, flex: 1, editor: { xtype: 'combo', id: 'mt', store: states, displayField: 'title', valueField: 'id', allowBlank: false } }, { header: 'title', dataIndex: 'title' } ], height: 200, width: 800, tbar: [{ text: 'Add Employee', iconCls: 'employee-add', handler : function() { rowEditing.cancelEdit(); // Create a model instance var r = Ext.create('Employee', { name: 'New Guy', email: 'new@sencha-test.com', start: new Date(), salary: 50000, active: true }); store.insert(0, r); rowEditing.startEdit(0, 0); } }, { itemId: 'removeEmployee', text: 'Remove Employee', iconCls: 'employee-remove', handler: function() { /** var sm = grid.getSelectionModel(); rowEditing.cancelEdit(); store.remove(sm.getSelection()); if (store.getCount() > 0) { sm.select(0); } */ }, disabled: true }], plugins: [rowEditing], listeners: { 'selectionchange': function(view, records) { grid.down('#removeEmployee').setDisabled(!records.length); } }, renderTo: Ext.getBody() }); });