简体   繁体   English

Sencha.ExtJs [4.2]:如何在列项目的处理程序中仅禁用一个操作按钮?

[英]Sencha.ExtJs[4.2]: How to disable only one action button within the handler of the column item?

The code snippet as following: 代码片段如下:

Ext.create("Ext.tree.Panel", {
    renderTo: $(".gsBasciInfo")[0],
    store: "basic_grid_store",
    useArrows: true,
    rootVisible: false,
    columns: {
        items: [{
            text: 'id',
            dataIndex: 'id',
            align: "right",
        }, {
            xtype: 'actioncolumn',
            items: [{
                xtype: 'button',
                iconCls: 'icon-edit',
                tooltip: '编辑',
                handler: function(view, rowIndex, colIndex, item, e, record) {
                    item.disable();
                    //do something
                    item.enable();
                }
           }]
        }]
    }
});

Let's say i have the grid panel like above, i'd like to disable this button once clicked, and then something running in background, after the thing is finished, enable this button. 假设我具有上面的网格面板,单击后我想禁用此按钮,然后在后台运行某些东西,完成操作后,启用此按钮。

But the only way i found just like my above code, the whole column of buttons were disabled which is not my wish. 但是,就像我上面的代码一样,我发现唯一的方法是禁用整个按钮列,这不是我的愿望。

My question is, how to accomplish what i want? 我的问题是,如何完成我想要的? Thanks 谢谢

item.disable() disables the whole column and this seem to be the correct logic (see this method ). item.disable()禁用整个列,这似乎是正确的逻辑(请参阅此方法 )。

The workaround is to implement your own disabling/enabling logic. 解决方法是实施您自己的禁用/启用逻辑。 I copy-pasted some parts from original disable/enable methods (eg view.disabledCls ). 我从原始的disable/enable方法(例如view.disabledCls )中复制粘贴了某些部分。 You may want to replace them with your own code. 您可能需要用自己的代码替换它们。 But anyway, here's the workaround: 但是无论如何,这是解决方法:

handler: function(view, rowIndex, colIndex, item, e, record) {
    var me = this;

    if (me.disabledEl === e.target) {
        return;
    }

    me.disabledEl = e.target;
    Ext.fly(e.target).addCls(view.disabledCls);

    //do something

    Ext.fly(e.target).removeCls(view.disabledCls);
    me.disabledEl = null;
}

Here's a demo . 这是一个演示

And by the way, no need to specify xtype: 'button' . 顺便说一句,无需指定xtype: 'button' ExtJs will use plain clickable <img> in any case. 在任何情况下,ExtJ都将使用可点击的<img>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM