-->

Extjs 6.5.3 Binding hidden property of widgetcolum

2019-08-31 04:13发布

问题:

I want to show/hide widgetcolumn of a grid with a property of my record.

I tried to do that with binding my value :

{
    xtype: 'grid',
    bind: {
        store: 'ActionList'
    },
    border: true,
    flex: 2,
    name: 'actionList',
    title: this.titleActionGrid,
    columns: [{
        xtype: 'widgetcolumn',
        height: 50,
        width: 65,
        widget: {
            xtype: 'button',
            text: '{sActionTitle}',
            scale: 'large',
            height: 45,
            width: 45,
            margin: 5
        },
        bind: {
            hidden: '{bIsHidden}'
        }
    }]
}

that didn't work so i search on internet and i find this fiddle : https://fiddle.sencha.com/#view/editor&fiddle/22rl

So i tried it with this part of code :

cell: {
    tools: {
        up: {
            bind: {
                hidden: '{record.bIsHidden}'
            }
        }
    }
}

But that didn't work, in fact the fiddle was on Modern and my code on classic..

I didn't find anything else and this is why i'm here, imploiring anyone to help me ;)

Thanks you by advance.

ExtJS Classic 6.5.3

回答1:

You could bind it like this:

Ext.create('Ext.grid.Panel', {
     renderTo: Ext.getBody(),
     store: store,
     border: true,
     flex: 2,
     name: 'actionList',
     title: this.titleActionGrid,
     columns: [{
             dataIndex: 'id',
         },
         {
             xtype: 'widgetcolumn',
             height: 50,
             width: 165,
             dataIndex: 'hide',
             widget: {
                 bind: {
                     text: '{record.id}',
                     hidden: '{record.hide}'
                 },
                 xtype: 'button',
                 scale: 'large',
                 height: 45,
                 width: 155,
                 margin: 5
             }
         }
     ]
 });


回答2:

You can use rowViewModel to bind by record for a widget column. Fiddle:

Ext.application({
    name: 'Fiddle',

    launch: function () {
        new Ext.grid.Panel({
            renderTo: document.body,
            viewModel: {
                data: {
                    actionTitle: 'Remove'
                }
            },
            store: {
                data: [{
                    name: 'A',
                    hidden: false
                }, {
                    name: 'B',
                    hidden: true
                }]
            },
            rowViewModel: true,
            columns: [{
                dataIndex: 'name',
                text: 'Name'
            }, {
                xtype: 'widgetcolumn',
                widget: {
                    xtype: 'button',
                    bind: {
                        text: '{actionTitle}',
                        hidden: '{record.hidden}'
                    },
                    margin: 5
                },
            }]
        });
    }
});