Ext JS 6.5 - 现代网格禁用无法正常工作

时间:2018-03-26 07:43:47

标签: extjs extjs6-modern extjs6.5

我正在使用Ext JS 6.5 modern。我有条件禁用grid组件,用户只有权查看grid没有其他人。

我尝试了disabled配置和disable方法,但无效。这是我的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组件的问题。

2 个答案:

答案 0 :(得分:1)

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

以下是示例Fiddle

答案 1 :(得分:1)

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

例如(编辑你的小提琴)

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>
相关问题