2012-08-01 65 views
0

我有一个GridWindow。当我点击该窗口的一行并单击删除按钮时,该行应该从窗口中删除。 (我想我必须remove it from Store and reload the grid, so the changes will be picked从本地网格删除记录

我无法获得点击事件并从商店中删除该行。我为此添加了按钮,但无法获取网格记录并将其从商店中删除并重新加载。

我的代码如下;像

Ext.define('MyApp.view.Boy', { 
    extend: 'Ext.window.Window', 
    alias: 'widget.boy', 
    height: 800, 
    width: 900, 
    layout: { 
     type: 'absolute' 
    }, 
    initComponent: function() { 
     var me = this; 
     Ext.applyIf(me, { 
      items: [ 
       { 
        xtype: 'gridpanel', 
        height: 500, 
        width: 800, 
        title: 'My Grid Panel', 
        store: 'School', 
        viewConfig: { 
        }, 
        columns: [ 
         { 
          xtype: 'gridcolumn', 
          dataIndex: 'Id', 
          text: 'id' 
         }, 
         { 
          xtype: 'gridcolumn', 
          dataIndex: 'name', 
          text: 'name' 
         } 
        ] 
       }, 
       { 
        xtype: 'button', 
        height: 40, 
        width: 150, 
        text: 'Remove', 
        listeners: { 
         click: { 
          fn: me.removebuttonclick, 
          scope: me 
         } 
        } 
       } 
      ] 
     }); 

     me.callParent(arguments); 
    }, 
    removebuttonclick: function(button, e, options) { 
     console.log('removebuttonclick'); 
    } 
}); 

回答

1

东西:

Ext.define('MyApp.view.Boy', { 
    extend: 'Ext.window.Window', 
    alias: 'widget.boy', 
    height: 800, 
    width: 900, 
    layout: { 
     type: 'absolute' 
    }, 
    initComponent: function() { 
     var me = this; 
     var this.grid = Ext.widget({ 
        xtype: 'gridpanel', 
        height: 500, 
        width: 800, 
        title: 'My Grid Panel', 
        store: 'School', 
        viewConfig: { 
        }, 
        columns: [ 
         { 
          xtype: 'gridcolumn', 
          dataIndex: 'Id', 
          text: 'id' 
         }, 
         { 
          xtype: 'gridcolumn', 
          dataIndex: 'name', 
          text: 'name' 
         } 
        ] 
       }); 
     Ext.applyIf(me, { 
      items: [ 
       this.grid, //oopsie 
       { 
        xtype: 'button', 
        height: 40, 
        width: 150, 
        text: 'Remove', 
        listeners: { 
         click: { 
          fn: me.removebuttonclick, 
          scope: me 
         } 
        } 
       } 
      ] 
     }); 

     me.callParent(arguments); 
    }, 
    removebuttonclick: function(button, e, options) { 
    var me = this; 
    Ext.Array.each(this.grid.getSelectionModel().selected,function(record, index,selectedRows){ 
      me.grid.getStore().remove(record); 
     }); 
    } 
}); 
+0

我得到'类型错误:this.grid是undefined'我如何解决这个问题? – 2012-08-01 14:30:05

+0

而不是像你指定的方式使用网格,有没有办法使用参数'按钮'获得'网格'? – 2012-08-01 14:30:54

+0

对不起,修正了例子中的类型错误。呃,如果不使用this.grid是可能的,但你最终会做各种不同的黑客(例如,将点击的范围作为网格传递,然后执行this.getSm()等,或者声明remove函数直接在配置中,或者使用绝对ID,或者走上dom,然后再回落(比听起来更复杂)) – Alex 2012-08-01 19:41:21