Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
public class TestClass111 { @AuraEnabled public static List<Account> getAccounts(){ List<Account> acList = new List<Account>(); acList = [Select Id, Name, Website From Account Where Website != NULL LIMIT 10]; return acList; } }
<aura:component controller="TestClass111" implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" > <aura:attribute name="accountList" type="Account[]"/> <aura:attribute name="columns" type="List"/> <aura:handler name="init" value="{!this}" action="{!c.onInit}"/> <h4>Lightning Data Table</h4> <lightning:datatable data="{!v.accountList}" columns="{!v.columns}" keyField="Id" hideCheckboxColumn="true" /> </aura:component>
({ onInit : function(component, event, helper) { var action = component.get("c.getAccounts"); action.setCallback(this, function(response){ if(response.getState() === 'SUCCESS'){ component.set("v.accountList", response.getReturnValue()); var columns = [ {label:'Id', fieldName:'Id', type:'String'}, {label:'Name', fieldName:'Name', type:'String'}, {label:'Website', fieldName:'Website', type: 'url', typeAttributes: { label: 'My Website Name', target:'_blank'}} ]; component.set("v.columns", columns); } else{ alert(response.getState()); } }); $A.enqueueAction(action); } })
Apex Controller
Lightning Component
Lightning Controller
Result:
Mark this as BEST ANSWER, if it solves your issue.
Assuming that you want to hyperlink a record in lightning.
May I suggest you please check with below link from the stack exchange community with a similar discussion which might help you further.
- https://salesforce.stackexchange.com/questions/212859/hyperlink-a-record-in-lightningdatatable
Hope this helps.Kindly mark this as solved if the reply was helpful so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.
Thanks,
Nagendra
Kindly check this link:
Hope this helps.
Aditya
Aditya Kaushal 6, that link solved my problem too. Thanks
{label:'yourField', fieldName:'Website', type: 'url', typeAttributes: { label: 'My Website Name', target:'_blank'}}
Click to be the best answer if it works.
Att,.
Josué Peixoto
({
doinit: function(component, event, helper) {
component.set('v.mycolumns', [
{label: 'Name', fieldName: 'linkName', type: 'url',
typeAttributes: {label: { fieldName: 'Name' },value:{fieldName: 'linkName'}, target: '_blank'}
},
{label: 'Phone', fieldName: 'Phone__c', type: 'text'},
{label: 'Email', fieldName: 'Email__c', type: 'text'}
]);
var action = component.get("c.fetchFamilyContacts");
action.setParams({
});
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
var records =response.getReturnValue();
records.forEach(function(record){
record.linkName = '/'+record.Id;
});
component.set("v.lstFC", response.getReturnValue());
}
});
$A.enqueueAction(action);
}
})
Follow below link for the solution,
https://developer.salesforce.com/forums/?id=9062I000000XuIjQAK
Hope this helps.