-1

I am working on Ext JS 6.5 modern. I have some condition to disable the grid component, user has only rights to view the grid no one else.

I have tried disabled config and disable method but not working. Here is my Fiddle.

Code snippet

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()

        });
    }
});

Somebody please help me with a solution for disabling the grid component.

Vy Do
  • 46,709
  • 59
  • 215
  • 313
Narendra Jadhav
  • 10,052
  • 15
  • 33
  • 44

2 Answers2

1

As a workaround we can use grid.setMasked(true);

Here is the example Fiddle.

Rohit Sharma
  • 1,402
  • 9
  • 20
1

Another approach is to set grid's hideMode to opacity and then set it to hidden (this.up('grid').setHidden(true);).

For Example (editing your 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()

    });

Also you need this css override:

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