简体   繁体   English

如何在Extjs中使用if条件禁用删除按钮

[英]How to disable the delete button using if condition in Extjs

How to disable the delete button using if condition in Extjs for ex;i want to disable the button if it satifies the given if condition else remain enabled. 我如何在Extjs for ex中使用if条件禁用删除按钮;我想在满足条件的情况下禁用按钮,否则条件仍保持启用状态。 if(validAction(entityHash.get('entity.xyz'),actionHash.get('action.delete'))) if(validAction(entityHash.get('entity.xyz'),actionHash.get('action.delete'))))

This is the grid Delete button code. 这是网格“删除”按钮代码。

Ext.reg("gridheaderbar-inActive", Ad.GridInActiveButton,{     
             xtype: 'tbspacer', width: 5
});  

Ad.GridCampDeleteButton = Ext.extend(Ext.Toolbar.Button, {

    //text: 'Delete',

    cls: 'ad-img-button',
    width:61,
    height:40,
    iconCls: 'ad-btn-icon',
    icon: '/webapp/resources/images/btn_del.png',
    handler:function(){

        statusChange(this.parentBar.parentGrid, 'Delete')
    }
});

create actioncolumn and make custom renderer: 创建actioncolumn并创建自定义渲染器:

{
    xtype: 'actioncolumn',
    width: 38,
    renderer: function (val, metadata, record) {
        this.items[0].icon = '${CONTEXT_PATH}/images/' + record.get('fileType') + '.png';
        this.items[0].disabled = !record.get('isDownloadActionEnable');
        this.items[1].disabled = !record.get('isDeleteActionEnable');
        metadata.style = 'cursor: pointer;';
        return val;
    },
    items: [
        {
            icon: '${CONTEXT_PATH}/images/pdf.png',  // Use a URL in the icon config
            tooltip: 'Download',
            handler: function (grid, rowIndex, colIndex) {
                //handle
            }
        },
        {
            icon: '${CONTEXT_PATH}/images/delete.png',  // Use a URL in the icon config
            tooltip: 'Delete',
            handler: function (grid, rowIndex, colIndex) {
                handle
            }
        }
    ]
}

in this example You see additionally how to change dynamically icon. 在此示例中,您还将看到如何动态更改图标。

One way to solve it is to attach a unique ID to your delete button and bind a listener to the selectionchange event of your SelectionModel, whenever the selection changes you can check whatever you want and enable/disable the button as you see fit. 解决此问题的一种方法是,将唯一的ID附加到删除按钮上,并将侦听器绑定到SelectionModel的selectionchange事件,每当选择更改时,您都可以检查所需内容并根据需要启用/禁用按钮。

ie. 即。

Ad.GridCampDeleteButton = Ext.extend(Ext.Toolbar.Button, {
    id: 'btnDelete',
    cls: 'ad-img-button',
...
});

and in your selectionmodel do something like this : 并在您的selectionmodel中执行以下操作:

var sm = new Ext.grid.CheckboxSelectionModel({
    ...
    ,listeners: {
        'selectionchange' : {
            fn: function(sm) {
                if (sm.hasSelection()) {
                    var selected = sm.getSelected();
                    if (selected.get('field') == value) {
                        Ext.getCmp('btnDelete').disable();
                    }
                    else {
                        Ext.getCmp('btnDelete').enable();
                    }
                }
            }
            ,scope: this
        }
    }
});

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

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