【问题标题】:Extjs - Not able to hide/unhide actioncolumn icon in specific rows in Grid panelExtjs - 无法隐藏/取消隐藏网格面板中特定行中的操作列图标
【发布时间】:2022-01-09 08:16:11
【问题描述】:

我希望根据我获得的行数据隐藏/取消隐藏我在操作列中添加的图标。我尝试使用 getClass 函数,但该图标在任何情况下都不会出现。不使用 getClass 函数而只使用 icon 键,我能够一直显示图标(在下面的代码中注释掉)。我在这里错过了什么?

this.columns = [{
        xtype: 'actioncolumn',
        itemId:'invalid_icon',
        sortable: false,
        menuDisabled: true,
        cls:'table_invalid_icon',
        width: 70,
        items: [{
            getClass: function(Value, metaData, record){
                if(record.data.name !== 'test' ){
                    return  "hideDisplay";
                }else{
                     return "showIcon";
                }
                    
            }
            //icon: 'image.svg'
        }]
}]

我有对应的css如下:

.showIcon{
   background:url('image.svg'); 
}
.hideDisplay{
  background:none; 
}

我还验证了 if 条件并且条件具有正确的值。关于我缺少什么的任何想法?

【问题讨论】:

    标签: extjs icons sencha-touch extjs4.2 gridpanel


    【解决方案1】:

    为什么你使用 brackground 而不是 icon 属性?图标是动态的还是静态的?

    .hidden {
        display: none
    }
    

    和工作样本:

    Ext.create('Ext.data.Store', {
        storeId: 'employeeStore',
        fields: ['firstname', 'lastname', 'seniority', 'dep', 'hired'],
        data: [{
            firstname: "Michael",
            lastname: "Scott"
        }, {
            firstname: "Dwight",
            lastname: "Schrute"
        }, {
            firstname: "Jim",
            lastname: "Halpert"
        }, {
            firstname: "Kevin",
            lastname: "Malone"
        }, {
            firstname: "Angela",
            lastname: "Martin"
        }]
    });
    
    Ext.create('Ext.grid.Panel', {
        title: 'Action Column Demo',
        store: Ext.data.StoreManager.lookup('employeeStore'),
        columns: [{
            text: 'First Name',
            dataIndex: 'firstname'
        }, {
            text: 'Last Name',
            dataIndex: 'lastname'
        }, {
            xtype: 'actioncolumn',
            width: 50,
            items: [{
                icon: 'https://docs.sencha.com/extjs/4.2.6/extjs-build/examples/shared/icons/fam/cog_edit.png', // Use a URL in the icon config
                tooltip: 'Edit',
                hidden: true,
                getClass: function (value, metaData, record, rowIndex) {
                    if (rowIndex % 2) {
                        return 'hidden'
                    }
                },
                handler: function (grid, rowIndex, colIndex) {
                    var rec = grid.getStore().getAt(rowIndex);
                    alert("Edit " + rec.get('firstname'));
                }
            }]
        }],
        width: 250,
        renderTo: Ext.getBody()
    });
    

    【讨论】:

    • 该图标是一个静态图标,不知何故我以前没有让它工作,但你的解决方案对我有用!谢谢!
    猜你喜欢
    • 2011-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多