How to perform View-Controller separation when using an “actioncolumn” (Ext.grid.column.Action)

前端 未结 2 968
盖世英雄少女心
盖世英雄少女心 2021-02-09 15:15

In ExtJS 4, I have a grid that contains an action column. Whenever that action is triggered, I want to execute \"my action\".

Without MVC, this would look like this:

2条回答
  •  余生分开走
    2021-02-09 15:32

    The problem is not in actioncolumn but in its items which are not ExtJs Widgets. This items are simple images. That's why we cannot assign handlers in control in such a way:

    this.control({
        'mygrid actioncolumn button[type=edit]' : this.onEdit
    

    This way, however, would be the best one.

    Unfortunately this way is impossible. But There is another way, which is almost as clean as the preferred one: make actioncolumn handler to fire grid's custom event (created by you):

    // view
    {
        xtype: 'actioncolumn',
        items: [{
            icon: 'http://cdn.sencha.io/ext-4.1.0-gpl/examples/shared/icons/fam/cog_edit.png',
            tooltip: 'Edit',
            handler: function(grid, rowIndex, colIndex) {
                // fire custom event "itemeditbuttonclick"
                this.up('grid').fireEvent('itemeditbuttonclick', grid, rowIndex, colIndex);
            }},
    
    // controller
    init: function() {
        this.control({
            'viewport > testpanel': {
                itemeditbuttonclick: this.onEdit,
                itemdeletebuttonclick: this.onDelete
            }
        });
    },
    

    Example

    Here is demo.

提交回复
热议问题