Hyperlink a Record in lightning:datatable
We can take help of the type: url
and typeAttributes: {label: { fieldName: 'linkLabel' }}
to show some useful link label of the column;
Working with Column Data
Here we have two options
type
possible values are(action, ..., url);typeAttributes
value depends on thetype
option value like for url we have (label, target);
Here is the example of the same: lightning:datatable
Below is the example of the options:
And we can also do this type adjustment just before assigning the columns settings to the attribute in the helper(if not want to do in the Apex):
({
getLightningTableData: function (component) {
var recLimit = component.get('v.recLimit');
var sColumn = component.get('v.fields');
var sObject = component.get('v.object');
var action = component.get('c.getsObjectRecords');
action.setParams({
ObjectName: sObject,
fieldstoget: sColumn,
recLimit: recLimit
});
action.setCallback(this, function (response) {
var state = response.getState();
if (state === 'SUCCESS') {
var rtnValue = response.getReturnValue();
rtnValue.tableColumn.forEach(function (column) {
switch (column.fieldName) {
case 'Show_Record__c':
column.type = 'url';
column['typeAttributes'] = { label: { fieldName: 'Name' } };
break;
default:
break;
}
});
component.set('v.mycolumn', rtnValue.tableColumn);
component.set('v.mydata', rtnValue.tableRecord);
}
});
$A.enqueueAction(action);
},
/* more methods */
})