Ext JS 6.5 - 禁用现代网格不工作

Ext JS 6.5 - modern grid disabled not working

我正在研究现代 Ext JS 6.5。我有一些条件可以禁用 grid 组件,用户只有权限查看 grid 没有其他人。

我试过了disabled config and disable method but not working. Here is my Fiddle

代码片段

Ext.application({
    name: 'Fiddle',

    launch: function () {
        Ext.create('Ext.data.Store', {

            storeId: 'gridStore',

            fields: ['name'],

            data: [{
                name: 'Test 1'
            }, {
                name: 'Test 2'
            }, {
                name: 'Test 3'
            }, {
                name: 'Test 4'
            }]
        });

        Ext.create({
            xtype: 'grid',

            layout: 'fit',

            fullscreen: true,

            title: 'Baisc grid example',

            store: 'gridStore',

            //Here I have put {disabled: true} but not working
            disabled: true,

            columns: [{
                text: 'Name',
                flex: 1,
                dataIndex: 'name'
            }],

            listeners: {
                childtap: function (grid, location, eOpts) {
                    alert('childtap');
                }
            },

            items: [{
                xtype: 'toolbar',
                items: {
                    xtype: 'button',
                    ui: 'action',
                    text: 'Disabled grid',
                    iconCls: 'x-fa fa-ban',
                    handler: function () {
                        //IT is also not working
                        this.up('grid').setDisabled(true);
                        this.up('grid').disable();
                    }
                }
            }]

            //renderTo:Ext.getBody()

        });
    }
});

有人请帮我解决禁用 grid 组件的问题。

作为解决方法,我们可以使用 grid.setMasked(true);

这里是例子Fiddle

另一种方法是将gridhideMode设置为opacity,然后设置为hiddenthis.up('grid').setHidden(true);)。

例如(编辑您的 fiddle)

Ext.create('Ext.data.Store', {

        storeId: 'gridStore',

        fields: ['name'],

        data: [{
            name: 'Test 1'
        }, {
            name: 'Test 2'
        }, {
            name: 'Test 3'
        }, {
            name: 'Test 4'
        }]

    });

    Ext.create({
        xtype: 'grid',

        layout: 'fit',

        fullscreen: true,

        title: 'Baisc grid example',

        store: 'gridStore',

        //Here I have put {disabled: true} but not working
        //disabled: true,

        hideMode: 'opacity',

        columns: [{
            text: 'Name',
            flex: 1,
            dataIndex: 'name'
        }],

        listeners: {
            childtap: function (grid, location, eOpts) {
                alert('childtap');
            }
        },

        items: [{
            xtype: 'toolbar',
            items: {
                xtype: 'button',
                ui: 'action',
                text: 'Disabled grid',
                iconCls: 'x-fa fa-ban',
                handler: function () {
                    this.up('grid').setHidden(true);
                }
            }
        }]

        //renderTo:Ext.getBody()

    });

您还需要这个 css 覆盖:

<style>
.x-hidden-opacity {
    opacity: 0.2 !important; //default is 0
    pointer-events: none;
}
</style>