function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Juan GarcíaJuan García 

Lightning datatable link

Hi,

I have a datatable, and I need a text column with hiperlink to the reference object.
I want a similar table to a standard list view, the name of the column record is a hiperlink of the record page

Example:
List view of a record:
User-added image

Datatable with a colum type url
User-added image

Datatable with a colum type text
User-added image

Code:
cmp.set('v.columns', [
            {label: 'Recurso', fieldName: 'Name', type: 'url', sortable: true, editable:'true', initialWidth: 120},
        ]);

Thanks
Best Answer chosen by Juan García
Alain CabonAlain Cabon
Hi,

You need two fields: a shown label and a value for the underlying url.

Component:

  cmp.set('v.columns', [ 
       {
                label: 'My Column Label',
                fieldName: 'myUrlField',
                type: 'url',
                typeAttributes: { label: {fieldName: 'myLabel'}},
                sortable:false
            },
... ]);

Controller:
                    myUrlField =   '/one/one.app?#/sObject/' + item.Id + '/view';
                    myLabel = 'My test of label':
                 

 

All Answers

Alain CabonAlain Cabon
Hi,

You need two fields: a shown label and a value for the underlying url.

Component:

  cmp.set('v.columns', [ 
       {
                label: 'My Column Label',
                fieldName: 'myUrlField',
                type: 'url',
                typeAttributes: { label: {fieldName: 'myLabel'}},
                sortable:false
            },
... ]);

Controller:
                    myUrlField =   '/one/one.app?#/sObject/' + item.Id + '/view';
                    myLabel = 'My test of label':
                 

 
This was selected as the best answer
Juan GarcíaJuan García
Hi,

Thank you very much. It works correctly.

Regards
Juan GarcíaJuan García
I used a new formula field with url:

Create Custom formula field.
Formula:
LEFT($Api.Partner_Server_URL_260, FIND( '/services', $Api.Partner_Server_URL_260)) + 's/detail/' + Id]
Put the field in Apex SOQL query
Then this code will be working.
{label: 'Case Number', fieldName: 'Show_Case__c', type: 'url',sortable: true,typeAttributes: {label:{ fieldName: 'CaseNumber'}}}

https://salesforce.stackexchange.com/questions/216841/record-url-in-lightningdatatable-in-community
Alain CabonAlain Cabon
Interesting your formula for an alternative.

Replacing (one/one.app?#/sObject) with (/lightning/o/). 

Why is Salesforce making this change?
To improve URL readability and address the issue of being directed to an unexpected location when accessing Lightning Experience URLs before authenticating. 

What happens to links I’ve saved, or see in email?
Don’t panic! The existing URLs will work for the foreseeable future. Links that you’ve saved or have in emails will be translated into the new enhanced URL format when they’re executed. If you have the enhanced URL format enabled for your org, that format is what you see in the browser address bar.

https://help.salesforce.com/articleView?id=000269064&language=en_US&type=1

These are equivalent alternatives and (one/one.app?#/sObject) is not the best nowadays indeed.
Naveen KNNaveen KN
datatable implementation with lightning web components 
https://www.codekiat.com/2019/08/salesforce-lightning-datatable-example-with-lwc-lightning-web-component.html