URL in <lightning:datatable>

You are absolutely right that URLs should be able to have individual labels and the good news it is already completed to be shipped in Spring '18 release.

In Spring, you will be able to use type attributes to set the same label for all rows:

typeAttributes: {
           label: 'Company website'
       }

Or use another field to set the label:

typeAttributes: {
           label: { fieldName: 'urlLabel' }
       }

Obviously we wanted this in Winter but we wanted to make typeAttributes extensible for all types.


Forgive me for my previous answer,which didn't explained anything. Actually we have to pass typeAttributes key "label" as an object which help to set which key of our data object will be displayed as label.

Component Markup:

 <aura:component implements="flexipage:availableForAllPageTypes" access="global">
     <aura:attribute name="testData" type="Object"/>
     <aura:attribute name="testColumns" type="List"/>

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

     <lightning:datatable data="{!v.testData}"
                     columns="{!v.testColumns}"
                     keyField="Id" />
</aura:component>

Controller Code:


({
    init : function(cmp, event, helper)
    {
        cmp.set('v.testColumns', [
                {
                  label: 'Link',
                  fieldName: 'link',
                  type: 'url',
                  typeAttributes: {
                    label: { fieldName: 'linkLabel' }
                  }
                }]);
        cmp.set('v.testData', [{
            id: '1',
            link: 'http://google.com',
            linkLable:'Google'
        }]);
    }
})

Result

enter image description here