0

Is there a way to have two buttons in one column using lightning Datatable? Would like to join the "Delete" and "Edit" buttons under the "Action" column.

enter image description here

Controller.js

({
    fetchAccounts : function(component, event, helper) {
        component.set('v.mycolumns', [
            {label: 'Action', type: "button", typeAttributes: {
                label: 'Edit',
                name: 'Edit',
                title: 'Edit',
                disabled: false,
                value: 'edit',
                iconPosition: 'left'
            }},
            {label: 'Action', type: "button", typeAttributes: {
                label: 'Delete',
                name: 'Delete',
                title: 'Delete',
                disabled: false,
                value: 'delete',
                iconPosition: 'left'
            }},
            {label: 'Contact Name', fieldName: 'linkName', type: 'url', 
             typeAttributes: {label: { fieldName: 'Name' }, target: '_self'}}, //_blank
            {label: 'Email', fieldName: 'Email', type: 'email'},
            {label: 'Phone', fieldName: 'Phone', type: 'phone'},
            {label: 'Department', fieldName: 'Department', type: 'Text'},
            {label: 'Description', fieldName: 'Description', type: 'Text'},
            {label: 'Fax', fieldName: 'Fax', type: 'Text'},
            {label: 'Department', fieldName: 'Department', type: 'Text'},         
            {label: 'Languages', fieldName: 'Languages__c', type: 'Text'},
            /*  {type: "button", typeAttributes: {
            label: 'View',
            name: 'View',
                title: 'View',
                disabled: false,
                value: 'view',
                iconPosition: 'left'
            }}
            */
        ]);
        var action = component.get("c.fetchAccts");
        action.setParams({
            parentId : component.get("v.recordId")
        });
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                var records =response.getReturnValue();
                records.forEach(function(record){
                    record.linkName = '/'+record.Id;
                });               
                component.set("v.acctList", response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
    }})

List.cmp

<div style="overflow-x: auto;">
    <lightning:datatable data="{! v.acctList }" 
                         columns="{! v.mycolumns }" 
                         keyField="id"
                         hideCheckboxColumn="false"
                         onrowaction="{!c.viewRecord}"/>
</div>
0

Using LWC base component (lightning-datatable), you can create custom data type in which you inject your custom component in any column(s).

You can create 2/more buttons in it and fire custom events with data and handle them in parent component.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.