I am trying to fetch List of sobjects and show them in data table. I want to add a hyperlink to record name. I am using @wired property to dynamically get records depending on the search term.
my test.js
@track data = [];
@track error;
@track columns = [{
label: 'Some name', fieldName: 'linkName', type: 'url', sortable: true,
typeAttributes: {label: { fieldName: 'Name' },value:{fieldName: 'linkName'}, target: '_blank'}}];
@wire(apexSearch,{searchTerm: "$searchTerm1"})
wiredTenders({error, data}) {
if (data) {
this.data = Object.assign({}, data);
var a = JSON.parse(JSON.stringify(this.data));
for (var i = 0; i < data.length; i++) {
console.log('1.5)'+(a[i]));
if(a[i].linkName) a[i].linkName = '/'+a[i].Id;
}
console.log('2)'+data);
} else if (error) {
this.error = error;
}
}
The linkName never gets filled i.e I cannot see a hyperlink and also no data shows up in data table. I checked that the var a
contains the list of objects.
I used this.data = Object.assign({}, data);
due to the explanation in this post: Uncaught TypeError: 'set' on proxy: trap returned falsish for property Name
Any suggestions would be helpful. Thanks!
Best Answer
here is a solution that works perfectly. I display a list of opportunity and add a hyperlink on the column name of the data table. To do that, you have to create a wrapper class in you apex controller like this:
note the nameUrl attribute, I'll use it in the js file.
here is the html file:
And Finally, the js file:
==========================================================================
Update
=========================================================================
This code below does the same thing without creating any wrapper class. We can only use JS.
Apex class