2015-01-21 39 views
2

我有一個'EmployeeList'視圖。裏面有一個網格。我需要處理來自控制器的動作列的單擊事件。下面是這個視圖:ExtJS grid:控制器中處理動作列的單擊事件

Ext.define('ExtApp.view.Employees', { 
    extend: 'Ext.panel.Panel', 
    alias: 'widget.employees', 
. 
. 
. 
. 
. 
}); 

此視圖包含一個網格:

xtype: 'grid', 
columns:[{ 
. 
. 
. 
. 
xtype: 'actioncolumn', 
       text: 'Delete', 
       width: 100, 
       items: [{ 
        icon: 'images/deleteEmployee.jpg', 
        tooltip: 'Delete' 
       }] 
}] 

如何處理actioncolumn的Click事件在我的控制?

這裏是控制器的代碼:

Ext.define('ExtApp.controller.Employees', { 
    extend: 'Ext.app.Controller', 
    refs: [{ 
     ref: 'employees', 
     selector: 'employees' 
    }], 
    init: function() { 
     //reference for the grid's actioncolumn needed here 

    } 
}); 

回答

7

如果你想處理與控制器的點擊,你將有一個處理程序添加到您的actioncolumn這樣的:

xtype:'actioncolumn', 
width:50, 
items: [{ 
    icon: 'extjs/examples/shared/icons/fam/cog_edit.png', // Use a URL in the icon config 
    tooltip: 'Edit', 
    handler: function(view, rowIndex, colIndex, item, e, record, row) { 
     this.fireEvent('itemClick', view, rowIndex, colIndex, item, e, record, row, 'edit'); 
    } 
}] 

,然後添加您的控制器中的itemClick事件的事件處理程序

init: function() { 
    this.control({ 
     'actioncolumn': { 
      itemClick: this.onActionColumnItemClick 
     } 
    }); 
}, 
onActionColumnItemClick : function(view, rowIndex, colIndex, item, e, record, row, action) { 
    alert(action + " user " + record.get('firstname')); 
} 

而且您應該ee它的工作,在這裏撥弄:https://fiddle.sencha.com/#fiddle/grb