根据行值隐藏 Lightning Datatable 中的按钮

Hide button inside Lightning Datatable based on row value

我需要根据同一行中的团队组名称隐藏 Lightning 数据表中的“查看”按钮

如果团队组名称为空,则必须隐藏查看按钮,如果团队名称不为空,则需要显示查看按钮

这是我的代码:

columns: [
    {label: "Course Title", fieldName: "CourseTitle", type: "text"},
    {label: "Team Group Name", fieldName: "TeamGroupName", type: "text"},
    {label: "Campus Name", fieldName: "CampusName", type: "text"},
    {label: "Course", fieldName: "Course", type: "text"},
    {label: "Section ID", fieldName: "SectionID", type: "text"},
    {label: "Session", fieldName: "Session", type: "text"},
    {label: "Course Level", fieldName: "CourseLevel", type: "text"},
    {label: "Term Length", fieldName: "TermLength", type: "text"},
    {type: "button", typeAttributes: {
            label: 'View',
            name: 'View',
            title: 'View',
            disabled: false,
            value: 'view',
            iconPosition: 'left'
        }}
]

组件:

<aura:component implements="force:appHostable"
controller="Teams_Controller">

<aura:attribute type="Account[]" name="acctList"/>
<aura:attribute name="mycolumns" type="List"/>

<aura:handler name="init" value="{!this}" action="{!c.fetchAccounts}"/>

<lightning:datatable data="{! v.acctList }" 
                     columns="{! v.mycolumns }" 
                     keyField="id"
                     hideCheckboxColumn="false"
                     onrowaction="{!c.viewRecord}"/>

我遇到了和你一样的问题。
我设法按照解决方案 here 解决了它。

编辑:我也在此处发布了解决方案。应该和你的情况类似。

组件:

<aura:component implements="force:appHostable"
   controller="AccountListController">

<aura:attribute type="AccountWrapper[]" name="acctList"/>
<aura:attribute name="mycolumns" type="List"/>

<aura:handler name="init" value="{!this}" action="{!c.fetchAccounts}"/>

<lightning:datatable data="{! v.acctList }" 
                     columns="{! v.mycolumns }" 
                     keyField="id"
                     hideCheckboxColumn="true"
                     onrowaction="{!c.viewRecord}"/>

组件控制器:

({

fetchAccounts : function(component, event, helper) {
    component.set('v.mycolumns', [
        {label: 'Account Name', fieldName: 'accName', type: 'text'},
        {label: 'Industry', fieldName: 'accIndustry', type: 'text'},
        {label: 'Type', fieldName: 'accType', type: 'text'},
        {label: 'Active?', fieldName: 'accActive', type: 'text'},
        {type: "button", typeAttributes: {
            label: 'View',
            name: 'View',
            title: 'View',
            disabled: { fieldName: 'isActive'},
            value: 'view',
            iconPosition: 'left'
        }}
    ]);
    var action = component.get("c.fetchAccts");
    action.setParams({
    });
    action.setCallback(this, function(response) {
        var state = response.getState();
        if (state === "SUCCESS") {
            component.set("v.acctList", response.getReturnValue());
        }
    });
    $A.enqueueAction(action);
},
viewRecord : function(component, event, helper) {
    var recId = event.getParam('row').accId;
    var actionName = event.getParam('action').name;
    if ( actionName == 'View') {
        var viewRecordEvent = $A.get("e.force:navigateToURL");
        viewRecordEvent.setParams({
            "url": "/" + recId
        });
        viewRecordEvent.fire();
    }
}
})

顶点类:

public class AccountWrapper {

@AuraEnabled
public String accName;
@AuraEnabled
public Boolean isActive;
@AuraEnabled
public String accIndustry;
@AuraEnabled
public String accType;
@AuraEnabled
public String accActive;   
@AuraEnabled
public String accId;
}

账户列表控制器:

public class AccountListController {

@AuraEnabled
public static List < AccountWrapper > fetchAccts() {
    List < AccountWrapper > listAcctWrapper = new List < AccountWrapper >();
    for ( Account acc : [ SELECT Id, Name, Industry, Type, Active__c FROM Account LIMIT 10 ] ) {
        AccountWrapper AccountWrap = new AccountWrapper();
        AccountWrap.accName = acc.Name;
        AccountWrap.isActive = acc.Active__c == 'Yes' ? true : false;
        AccountWrap.accIndustry = acc.Industry;
        AccountWrap.accType = acc.Type;
        AccountWrap.accActive = acc.Active__c;
        AccountWrap.accId = acc.Id;
        listAcctWrapper.add(AccountWrap);
    }
    return listAcctWrapper;
  }
}

希望对你有帮助。