2

How do you set an action on a column to Navigate to Sobject record?

Or when the name of the record is clicked fire an action.

Doesn't appear you can do it with the base component.

<lightning:card title="Entities">
    <lightning:datatable data="{!v.Contact}" 
        columns="{!v.mycolumns}" 
        keyField="Id"
        />

({
init : function(component, event, helper) {
    component.set('v.mycolumns', [
        {label: 'ID', fieldName: 'Id', type: 'Id'},
        {label: 'Full Name', fieldName: 'Name', type: 'text'},
        {label: 'First Name', fieldName: 'FirstName', type: 'text'},
        {label: 'Last Name', fieldName: 'LastName', type: 'text'},
        {label: 'Phone, Primary', fieldName: 'Phone', type: 'phone'},
        {label: 'Phone, Secondary', fieldName: 'Phone_Secondary__c', type: 'phone'},
        {label: 'Email', fieldName: 'Email', type: 'Email'},
        {label: 'Business Fax', fieldName: 'Fax', type: 'phone'},
        {label: 'Street', fieldName: 'MailingStreet', type: 'text'},
        {label: 'City', fieldName: 'MailingCity', type: 'text'},
        {label: 'State', fieldName: 'MailingState', type: 'text'},
        {label: 'Zip', fieldName: 'MailingPostalCode', type: 'number'},
    ]);
    helper.getData(component);
},

2 Answers 2

0

For now - this is not possible.

I asked the same question, and got an answer that it will be supported in the next release - see my question and the answers to it Here:

Winter 18 problems

0

On your datatable you add a listener to row selection:

onrowselection="{! c.navigateToSObject }"/>

Then handle the event and redirect to the object.

navigateToSObject: function (cmp, event) {
    var selectedRows = event.getParam('selectedRows');
    var navEvt = $A.get("e.force:navigateToSObject");
    navEvt.setParams({
      "recordId": selectedRows[0].ID,
    });
    navEvt.fire();
}
1
  • The problem with using onrowselection is that you can click on more than one at time if you wanted to add more actions on the list of records. Commented Nov 21, 2017 at 21:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .