extjsiconssencha-touchextjs4.2gridpanel

Extjs - Not able to hide/unhide actioncolumn icon in specific rows in Grid panel


I am looking to hide/unhide an icon which I have added in action column based on the row data I get. I tried using the getClass function, but the icon never shows up in any scenario. Without using the getClass function and just using the icon key, I was able to show the icon all the time (commented out in the code below). What am I missing here?

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'
        }]
}]

I have the corresponding css as below:

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

I have also verified the if condition and the condition has the correct value. Any ideas on what I am missing?


Solution

  • Why do you use brackground instead of icon property? Is the icon dynamic or static?

    .hidden {
        display: none
    }
    

    And working sample:

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