I currently have a custom list view LWC that displays a list of custom objects and its fields. I want to have a hyperlink on a specific field that takes the user to the record page.

So, the html for the datatable looks like this:

<lightning-datatable key-field="Id" data={data} columns={columns}>
  • Can you add a little more detail from your javascript controller? I added an answer, but it would be more useful if I could see a few more implementation details. Jun 22, 2021 at 20:03

1 Answer 1


I don't know what particular field you are wanting to use to link to the record, but you need two thinks for a link in a datatable -

  • A URL Name
  • A URL Link

You need to add these after you get your results from the server.

Here is one example:

  getData({param: yourparam})
  .then(result => {
    let resultList = [];
    result.forEach(r => {
      let record = { ...r };
      //here is the important bit - generating yourUrl and yourUrlName
      record.yourUrl = `/lightning/r/<yoursobjectname>/${r.Id}/view`;
      record.yourUrlName = r.Name;
    this.itemsForCurrentView = resultList;
  .catch(error => {//log error });

Then in your column definition, you need to reference these values to generate the url link in your table.

columns = 
...other columns
  label: 'Record Link',
  sortable: true,
  fieldName: 'yourUrl',
  type: 'url',
  typeAttributes: { label: { fieldName: 'yourUrlName' }, target: '_blank' }

One reason NOT to use the NavigationMixin is that you can't right click on the record and open in a new tab.

Which is endlessly frustrating for users.

  • 1
    Thank you! This is very helpful!
    – Lia
    Jun 22, 2021 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.