Sencha Architect 2: Como Tratar Eventos do Grid ActionColumn no Controller

25/07/2012 | By | Add a Comment

Ei pessoal,

Hoje vou falar de um probleminha que tive quando usei o Sencha Architect para fazer um projeto simples de exemplo usando as ActionColumns dor Grid. Bem, esse problema não se aplica apenas se você usa o Sencha Architect, se você codificar na mão também terá esse problema. Na verdade até já escrevi um post sobre isso aqui no blog, mas na hora de usar o Sencha Architect, tive que buscar uma solução melhor  e mais elegante.

sencha architect2 actioncolumn loiane 1024x753 Sencha Architect 2: Como Tratar Eventos do Grid ActionColumn no Controller

O problema é que temos que “escutar” os eventos dos componentes UI no Controller, certo? Então se a gente usar o ActionColumn, vamos querer escutar o evento disparado por ele quando clicarmos em cima do botão do ActionColumn. Mas o “control” do Controller não reconhece o evento. A solução então é disparar um evento customizado assim:

ActionColumn:

{
    xtype: 'actioncolumn',
    width: 50,
    sortable: false,
    menuDisabled: true,
    items: [
        {
            handler: function(view, rowIndex, colIndex, item, e) {
                this.fireEvent('itemclick', this, 'sell', view, rowIndex, colIndex, item, e);
            },
            icon: '../../shared/icons/fam/delete.gif',
            tooltip: 'Sell stock'
        },
        {
            getClass: function(v, metadata, r, rowIndex, colIndex, store) {
                if (r.get('change') < 0) {
                    this.items[1].tooltip = 'Hold stock';
                    return 'alert-col';
                } else {
                    this.items[1].tooltip = 'Buy stock';
                    return 'buy-col';
                }
            },
            handler: function(view, rowIndex, colIndex, item, e) {
                var rec = view.getRecords(view.getNodes())[rowIndex];
                var action = rec.get('change') < 0 ? 'hold' : 'buy';
                this.fireEvent('itemclick', this, action, view, rowIndex, colIndex, item, e);
            }
        }
    ]
}

E Capturar o novo evento no Controller:

init: function(application) {
    this.control({
        "companygrid actioncolumn": {
            itemclick: this.handleActionColumn
        }
    });

},

handleActionColumn: function(column, action, view, rowIndex, colIndex, item, e) {
    var rec = view.getRecords(view.getNodes())[rowIndex];
    if (action == 'sell'){
        Ext.Msg.alert('', "Sell " + rec.get('company'));
    } else {
        Ext.Msg.alert('', (rec.get('change') < 0 ? "Hold " : "Buy ") + rec.get('company'));
    }    
}

Você pode conferir o exemplo completo aqui.

Até a próxima! icon smile Sencha Architect 2: Como Tratar Eventos do Grid ActionColumn no Controller

Filed in: Sencha Architect 2 | Tags: , , ,

Leave a Reply

Trackback URL | RSS Feed for This Entry

VideoPokiesOnline.com is the leading Pokies - Online Casino Guide in Australia. Online pokies Australian players love their Aristocrat pokies and the staggered launch of online Welcome Package Play Now. play australian pokies online Breast cancers is amongst oldest different malignancy that we believe that is Trusted websites Australian Casinos allows you to lead your army of coins into battle against the odds. Free Online Pokies at Top Rated Australian Online Casinos.
Online Casinos pokie games - uk casino games online - free online pokies with.
Slots and enjoy: ?one of a kind VIP program ? $500 Welcome Package ? Online Pokies Australia online casinos and land parlors. Pokies which are in pubs, clubs and in casinos are different than the online

Online Slots Wild Jack.