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);
},
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();
}
  • 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. – Michael Yocca Nov 21 '17 at 21:39

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.