[SalesForce] How to set typeattribute in LWC datatable

 {label:'FCU Trigger',   type: "button",
                        typeAttributes: {  
                            label: 'Initiate',  
                            name: 'initiate',  
                            title: 'View',  
                            disabled: false,  
                            value: 'view',  
                            iconPosition: 'left', 
                            variant:"brand",
                            class:"slds-visible" 
                        }},

I want to set class attribute to slds-hidden

obj.typeAttributes.setAttribute('class', 'slds-hidden');

This is not working thrwoing error in console e.typeattribute.setattribute is not a function

 renderedCallback() {

    var table = this.template.querySelector('lightning-datatable');
    if(table!= null)
    {
     var rows = table.data;
     var col = table.columns;

            rows.forEach(function(element){
                if(element.SME_Document_Collection_Mode__c === 'Login via link')
                {
                    col.forEach(function(obj){
                        if(obj.label === 'FCU Trigger')
                        {
                            obj.typeAttributes.setAttribute('class', 'slds-hidden');  
                            alert(obj.typeAttributes.class); 
                        }
                    });
                }
                //alert(element);
            });
    }      
}

Best Answer

It seems like you are trying to hide the button wherever SME_Document_Collection_Mode__c is Login via link. Modifying the columns will affect the whole table as each object in columns define the structure of whole column and not single cell in column.

You can implement one more column at run time which will decide which class to append. Below is the sample:

@track columns = [
    { label: 'Name', fieldName: 'Name' },
    { label: 'Mode', fieldName: 'SME_Document_Collection_Mode__c' },
    {
        label: 'FCU Trigger', type: "button",
        typeAttributes: {
            label: 'Initiate',
            name: 'initiate',
            title: 'View',
            disabled: false,
            value: 'view',
            iconPosition: 'left',
            variant: "brand",
            class: { fieldName: 'ModeClass' }
        }
    }
];

connectedCallback() { // or wire service or any other method where you are getting data
    this.data = this.data.map(record => {
        record.ModeClass = (record.SME_Document_Collection_Mode__c === 'Login via link') ? 'slds-hidden' : 'slds-visible';
        return record;
    });
}

Notice the way class is getting its value - from another field called ModeClass which is being created at run time depending on the field SME_Document_Collection_Mode__c.

Playground link output:

enter image description here