Insert a link in lightning datatable Column Value

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite
1












I am trying to insert a link in a result column of lightning:datatable



Below is the code snippet :



Datatable Code:



 <lightning:datatable data="! v.contactList " 
columns="! v.mycolumns "
keyField="id"
onrowselection = "!c.checkboxFetch"
hideCheckboxColumn="false"
onrowaction="!c.checkboxFetch"
class="tableCss"
tabindex="1"/>




Controller Code:



label: 'Customer Name', fieldName: 'CustomerName__c', type: 'url', 
sortable:"false",
typeAttributes:
label: 'Customer Name',
fieldName: 'CustomerName__c',
title: 'View',
disabled: false,
value: 'view',
iconPosition: 'left',
url: 'www.google.com',
, ,




However, in the result I am not able to link the column with the mentioned url and when clicking on the hyperlink it is redirecting to a localhost url like 172.9.0.1 (something like this)




Any idea on how to redirect to the url : www.google.com ? Also, the
customer result from the variable iteration
component.set('v.mycolumns' is not displaying the result.
Rather it displaying the static value : Customer Name











share|improve this question























  • You have to set the column type as url and in in data, you have to separately define the link you want the users to redirect to. Have a look at this example provided in the documentation, developer.salesforce.com/docs/component-library/bundle/…
    – Ranga
    Sep 16 at 11:43
















up vote
1
down vote

favorite
1












I am trying to insert a link in a result column of lightning:datatable



Below is the code snippet :



Datatable Code:



 <lightning:datatable data="! v.contactList " 
columns="! v.mycolumns "
keyField="id"
onrowselection = "!c.checkboxFetch"
hideCheckboxColumn="false"
onrowaction="!c.checkboxFetch"
class="tableCss"
tabindex="1"/>




Controller Code:



label: 'Customer Name', fieldName: 'CustomerName__c', type: 'url', 
sortable:"false",
typeAttributes:
label: 'Customer Name',
fieldName: 'CustomerName__c',
title: 'View',
disabled: false,
value: 'view',
iconPosition: 'left',
url: 'www.google.com',
, ,




However, in the result I am not able to link the column with the mentioned url and when clicking on the hyperlink it is redirecting to a localhost url like 172.9.0.1 (something like this)




Any idea on how to redirect to the url : www.google.com ? Also, the
customer result from the variable iteration
component.set('v.mycolumns' is not displaying the result.
Rather it displaying the static value : Customer Name











share|improve this question























  • You have to set the column type as url and in in data, you have to separately define the link you want the users to redirect to. Have a look at this example provided in the documentation, developer.salesforce.com/docs/component-library/bundle/…
    – Ranga
    Sep 16 at 11:43












up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





I am trying to insert a link in a result column of lightning:datatable



Below is the code snippet :



Datatable Code:



 <lightning:datatable data="! v.contactList " 
columns="! v.mycolumns "
keyField="id"
onrowselection = "!c.checkboxFetch"
hideCheckboxColumn="false"
onrowaction="!c.checkboxFetch"
class="tableCss"
tabindex="1"/>




Controller Code:



label: 'Customer Name', fieldName: 'CustomerName__c', type: 'url', 
sortable:"false",
typeAttributes:
label: 'Customer Name',
fieldName: 'CustomerName__c',
title: 'View',
disabled: false,
value: 'view',
iconPosition: 'left',
url: 'www.google.com',
, ,




However, in the result I am not able to link the column with the mentioned url and when clicking on the hyperlink it is redirecting to a localhost url like 172.9.0.1 (something like this)




Any idea on how to redirect to the url : www.google.com ? Also, the
customer result from the variable iteration
component.set('v.mycolumns' is not displaying the result.
Rather it displaying the static value : Customer Name











share|improve this question















I am trying to insert a link in a result column of lightning:datatable



Below is the code snippet :



Datatable Code:



 <lightning:datatable data="! v.contactList " 
columns="! v.mycolumns "
keyField="id"
onrowselection = "!c.checkboxFetch"
hideCheckboxColumn="false"
onrowaction="!c.checkboxFetch"
class="tableCss"
tabindex="1"/>




Controller Code:



label: 'Customer Name', fieldName: 'CustomerName__c', type: 'url', 
sortable:"false",
typeAttributes:
label: 'Customer Name',
fieldName: 'CustomerName__c',
title: 'View',
disabled: false,
value: 'view',
iconPosition: 'left',
url: 'www.google.com',
, ,




However, in the result I am not able to link the column with the mentioned url and when clicking on the hyperlink it is redirecting to a localhost url like 172.9.0.1 (something like this)




Any idea on how to redirect to the url : www.google.com ? Also, the
customer result from the variable iteration
component.set('v.mycolumns' is not displaying the result.
Rather it displaying the static value : Customer Name








lightning lightning-experience slds datatable lightning-datatable






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 16 at 11:57

























asked Sep 16 at 11:16









Jayati Jaiswal

238




238











  • You have to set the column type as url and in in data, you have to separately define the link you want the users to redirect to. Have a look at this example provided in the documentation, developer.salesforce.com/docs/component-library/bundle/…
    – Ranga
    Sep 16 at 11:43
















  • You have to set the column type as url and in in data, you have to separately define the link you want the users to redirect to. Have a look at this example provided in the documentation, developer.salesforce.com/docs/component-library/bundle/…
    – Ranga
    Sep 16 at 11:43















You have to set the column type as url and in in data, you have to separately define the link you want the users to redirect to. Have a look at this example provided in the documentation, developer.salesforce.com/docs/component-library/bundle/…
– Ranga
Sep 16 at 11:43




You have to set the column type as url and in in data, you have to separately define the link you want the users to redirect to. Have a look at this example provided in the documentation, developer.salesforce.com/docs/component-library/bundle/…
– Ranga
Sep 16 at 11:43










1 Answer
1






active

oldest

votes

















up vote
5
down vote













Your Type Attributes, and likely the underlying data, aren't set up properly for a url type entry.



Your url item should correspond to the column in your data that contains a URL value (not the link's title or the column title). You can use the typeAttributes map to supply three additional parameters:



  • label

  • target

  • tooltip

Your columns entry should look something like this:




label: 'Customer Name',
fieldName: 'CustomerName__c', // This field should have the actual URL in it.
type: 'url',
sortable: "false",
typeAttributes:
label:
fieldName: 'UserReadableName__c'
// whatever field contains the actual label of the link
,
target: '_blank', // or as desired
tooltip: 'Open the customer page' // or as desired




Then, your CustomerName__c column in your data must contain an actual URL (not a Salesforce Id or anything else). If it doesn't, you can add a synthetic column to your data, such as



contactsList.forEach(function(contact) 
contact.SearchURL = 'https://google.com/search?q=' + contact.CustomerName__c;






share|improve this answer




















  • Thanks for the reply I am still not able to populate the url and getting the below error when tired the foreach approach : This page has an error. You might just need to refresh it. Action failed: c:dataTableCmp$controller$doInit [contactList is not defined] Failing descriptor: c:dataTableCmp$controller$doInit Adding the label, target, tooltip to the datatable typeAttributes does not work as it is showing blank value on the UI.
    – Jayati Jaiswal
    Sep 17 at 9:32











  • Well, you can't paste my code into a location where contactList is not defined. You may need to adapt this to fit the architecture of your component, and you certainly will need to wait to execute it until your server callback returns, if you're executing a query in an Apex controller.
    – David Reed
    Sep 17 at 13:16










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "459"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f232660%2finsert-a-link-in-lightning-datatable-column-value%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
5
down vote













Your Type Attributes, and likely the underlying data, aren't set up properly for a url type entry.



Your url item should correspond to the column in your data that contains a URL value (not the link's title or the column title). You can use the typeAttributes map to supply three additional parameters:



  • label

  • target

  • tooltip

Your columns entry should look something like this:




label: 'Customer Name',
fieldName: 'CustomerName__c', // This field should have the actual URL in it.
type: 'url',
sortable: "false",
typeAttributes:
label:
fieldName: 'UserReadableName__c'
// whatever field contains the actual label of the link
,
target: '_blank', // or as desired
tooltip: 'Open the customer page' // or as desired




Then, your CustomerName__c column in your data must contain an actual URL (not a Salesforce Id or anything else). If it doesn't, you can add a synthetic column to your data, such as



contactsList.forEach(function(contact) 
contact.SearchURL = 'https://google.com/search?q=' + contact.CustomerName__c;






share|improve this answer




















  • Thanks for the reply I am still not able to populate the url and getting the below error when tired the foreach approach : This page has an error. You might just need to refresh it. Action failed: c:dataTableCmp$controller$doInit [contactList is not defined] Failing descriptor: c:dataTableCmp$controller$doInit Adding the label, target, tooltip to the datatable typeAttributes does not work as it is showing blank value on the UI.
    – Jayati Jaiswal
    Sep 17 at 9:32











  • Well, you can't paste my code into a location where contactList is not defined. You may need to adapt this to fit the architecture of your component, and you certainly will need to wait to execute it until your server callback returns, if you're executing a query in an Apex controller.
    – David Reed
    Sep 17 at 13:16














up vote
5
down vote













Your Type Attributes, and likely the underlying data, aren't set up properly for a url type entry.



Your url item should correspond to the column in your data that contains a URL value (not the link's title or the column title). You can use the typeAttributes map to supply three additional parameters:



  • label

  • target

  • tooltip

Your columns entry should look something like this:




label: 'Customer Name',
fieldName: 'CustomerName__c', // This field should have the actual URL in it.
type: 'url',
sortable: "false",
typeAttributes:
label:
fieldName: 'UserReadableName__c'
// whatever field contains the actual label of the link
,
target: '_blank', // or as desired
tooltip: 'Open the customer page' // or as desired




Then, your CustomerName__c column in your data must contain an actual URL (not a Salesforce Id or anything else). If it doesn't, you can add a synthetic column to your data, such as



contactsList.forEach(function(contact) 
contact.SearchURL = 'https://google.com/search?q=' + contact.CustomerName__c;






share|improve this answer




















  • Thanks for the reply I am still not able to populate the url and getting the below error when tired the foreach approach : This page has an error. You might just need to refresh it. Action failed: c:dataTableCmp$controller$doInit [contactList is not defined] Failing descriptor: c:dataTableCmp$controller$doInit Adding the label, target, tooltip to the datatable typeAttributes does not work as it is showing blank value on the UI.
    – Jayati Jaiswal
    Sep 17 at 9:32











  • Well, you can't paste my code into a location where contactList is not defined. You may need to adapt this to fit the architecture of your component, and you certainly will need to wait to execute it until your server callback returns, if you're executing a query in an Apex controller.
    – David Reed
    Sep 17 at 13:16












up vote
5
down vote










up vote
5
down vote









Your Type Attributes, and likely the underlying data, aren't set up properly for a url type entry.



Your url item should correspond to the column in your data that contains a URL value (not the link's title or the column title). You can use the typeAttributes map to supply three additional parameters:



  • label

  • target

  • tooltip

Your columns entry should look something like this:




label: 'Customer Name',
fieldName: 'CustomerName__c', // This field should have the actual URL in it.
type: 'url',
sortable: "false",
typeAttributes:
label:
fieldName: 'UserReadableName__c'
// whatever field contains the actual label of the link
,
target: '_blank', // or as desired
tooltip: 'Open the customer page' // or as desired




Then, your CustomerName__c column in your data must contain an actual URL (not a Salesforce Id or anything else). If it doesn't, you can add a synthetic column to your data, such as



contactsList.forEach(function(contact) 
contact.SearchURL = 'https://google.com/search?q=' + contact.CustomerName__c;






share|improve this answer












Your Type Attributes, and likely the underlying data, aren't set up properly for a url type entry.



Your url item should correspond to the column in your data that contains a URL value (not the link's title or the column title). You can use the typeAttributes map to supply three additional parameters:



  • label

  • target

  • tooltip

Your columns entry should look something like this:




label: 'Customer Name',
fieldName: 'CustomerName__c', // This field should have the actual URL in it.
type: 'url',
sortable: "false",
typeAttributes:
label:
fieldName: 'UserReadableName__c'
// whatever field contains the actual label of the link
,
target: '_blank', // or as desired
tooltip: 'Open the customer page' // or as desired




Then, your CustomerName__c column in your data must contain an actual URL (not a Salesforce Id or anything else). If it doesn't, you can add a synthetic column to your data, such as



contactsList.forEach(function(contact) 
contact.SearchURL = 'https://google.com/search?q=' + contact.CustomerName__c;







share|improve this answer












share|improve this answer



share|improve this answer










answered Sep 16 at 14:07









David Reed

20.6k31640




20.6k31640











  • Thanks for the reply I am still not able to populate the url and getting the below error when tired the foreach approach : This page has an error. You might just need to refresh it. Action failed: c:dataTableCmp$controller$doInit [contactList is not defined] Failing descriptor: c:dataTableCmp$controller$doInit Adding the label, target, tooltip to the datatable typeAttributes does not work as it is showing blank value on the UI.
    – Jayati Jaiswal
    Sep 17 at 9:32











  • Well, you can't paste my code into a location where contactList is not defined. You may need to adapt this to fit the architecture of your component, and you certainly will need to wait to execute it until your server callback returns, if you're executing a query in an Apex controller.
    – David Reed
    Sep 17 at 13:16
















  • Thanks for the reply I am still not able to populate the url and getting the below error when tired the foreach approach : This page has an error. You might just need to refresh it. Action failed: c:dataTableCmp$controller$doInit [contactList is not defined] Failing descriptor: c:dataTableCmp$controller$doInit Adding the label, target, tooltip to the datatable typeAttributes does not work as it is showing blank value on the UI.
    – Jayati Jaiswal
    Sep 17 at 9:32











  • Well, you can't paste my code into a location where contactList is not defined. You may need to adapt this to fit the architecture of your component, and you certainly will need to wait to execute it until your server callback returns, if you're executing a query in an Apex controller.
    – David Reed
    Sep 17 at 13:16















Thanks for the reply I am still not able to populate the url and getting the below error when tired the foreach approach : This page has an error. You might just need to refresh it. Action failed: c:dataTableCmp$controller$doInit [contactList is not defined] Failing descriptor: c:dataTableCmp$controller$doInit Adding the label, target, tooltip to the datatable typeAttributes does not work as it is showing blank value on the UI.
– Jayati Jaiswal
Sep 17 at 9:32





Thanks for the reply I am still not able to populate the url and getting the below error when tired the foreach approach : This page has an error. You might just need to refresh it. Action failed: c:dataTableCmp$controller$doInit [contactList is not defined] Failing descriptor: c:dataTableCmp$controller$doInit Adding the label, target, tooltip to the datatable typeAttributes does not work as it is showing blank value on the UI.
– Jayati Jaiswal
Sep 17 at 9:32













Well, you can't paste my code into a location where contactList is not defined. You may need to adapt this to fit the architecture of your component, and you certainly will need to wait to execute it until your server callback returns, if you're executing a query in an Apex controller.
– David Reed
Sep 17 at 13:16




Well, you can't paste my code into a location where contactList is not defined. You may need to adapt this to fit the architecture of your component, and you certainly will need to wait to execute it until your server callback returns, if you're executing a query in an Apex controller.
– David Reed
Sep 17 at 13:16

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f232660%2finsert-a-link-in-lightning-datatable-column-value%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)