Add Hyperlink Column in LWC Datatable

by Rijwan Mohmmed

Hello friends, today we will discuss How to Add Hyperlink Column in LWC Datatable. When the type of column for the data table is URL, Fields with Datatype URL are displayed as Links by default. However, if the field is not of type URL, we need to customize it to make it clickable in Datatable.

Also, check this: Use createRecord in LWC Salesforce


Key Highlights :

  1. Can make clickable record name column.
  2. Navigate to a particular record when clicking the link.

Code :

AccountDataController.cls :

public class AccountDataController {
    @AuraEnabled(Cacheable = true)
    public static List<Account> getAccounts(){
      return [SELECT Id, Name, Industry, Type, Phone, Rating, AccountNumber FROM Account ORDER BY Name LIMIT 10];

linkLWCDatatable.HTML :

	<lightning-card title="Add Hyperlink Column in LWC Datatable" icon-name="standard:account">
		<div class="slds-p-horizontal_small">
			<div if:true={data}>
				<lightning-datatable data={data} columns={columns} key-field="Id"></lightning-datatable>


import { LightningElement, wire, track } from 'lwc';
import getAccounts from '@salesforce/apex/AccountDataController.getAccounts';

const columns = [
        label: 'Name',
        fieldName: 'accLink',
        type: 'url',
        typeAttributes: { label: { fieldName: 'Name' }, target: '_blank' }
    }, {
        label: 'Type',
        fieldName: 'Type',
        type: 'text',
    }, {
        label: 'Phone',
        fieldName: 'Phone',
        type: 'Phone',
    }, {
        label: 'AccountNumber',
        fieldName: 'AccountNumber',
        type: 'text'

export default class LinkLWCDatatable extends LightningElement {
    data = [];
    columns = columns;

    wireAccounts({ error, data }) {
        if (data) {
            data = JSON.parse(JSON.stringify(data));

            data.forEach(res => {
                res.accLink = '/' + res.Id;

   = data;
            this.error = undefined;
        } else if (error) {
            this.error = error;


<?xml version="1.0"?>
<LightningComponentBundle xmlns="">

Output :


Reference :

  1. LWC Datatable
What’s your Reaction?

You may also like


Pranav June 12, 2023 - 7:07 am

Hi… I have to make Opportunity Name Clickable in Custom table in LWC. Wheather I have fetched The Data using Wired Method and Iterated Property in HTML. then How we can make Opportunity Name as clickable which redirect to that particular Opportunity Record Page.

Rijwan Mohmmed June 12, 2023 - 12:08 pm

I thing this one is already done in the given task

Eduardo Cisneros December 18, 2023 - 7:09 pm

This worked very well for me, I have a table in LWC to consult pending approval steps, it is just what I needed, thank you.

Rijwan Mohmmed December 19, 2023 - 4:13 am

Thanks you Eduardo Cisneros

Simran January 2, 2024 - 6:07 am

what if we have a parameter in the getAccounts method in the class?

Rijwan Mohmmed January 2, 2024 - 6:22 am

Hi @Simran , Can you please more about your query.

Simran January 2, 2024 - 6:45 am

So my req is that i need to create a Quote list in Opportunity Page with certain where clause because of which i need to pass Quote Id in the apex class as mentioned below in the comment. The problem i am facing is that i am either seeing the url in the record in the Name section instead of the Name and upon clicking on the Quote Name it should redirect to the Quote

Rijwan Mohmmed January 2, 2024 - 9:31 am

Hi @Simran, the first issue is element.Name = ‘/’+element.Id;
Name is standard field, and there is no field of ‘Quote Name’

Rijwan Mohmmed January 2, 2024 - 9:32 am

We can also connect on Topmate just book the slot

Simran January 2, 2024 - 6:27 am

my apex class is
public class MCOnline_QuoteList {
public static List getQuote(String oppId){

List response2 = new List();
String rectype = ‘Contract Quote’;
String quotelist = ‘select id,QuoteNumber, Name, ExpirationDate, Subtotal, TotalPrice, CreatedBy.Name,CreatedById,, IsSyncing from Quote where OpportunityId =: oppId and RecordType.Name =: rectype’;
response2 = Database.query(quotelist);
system.debug(‘Response2 ‘+response2);

}catch(Exception exp){

return response2;


import { LightningElement, wire, api, track } from ‘lwc’;
import getDetails from ‘@salesforce/apex/MCOnline_QuoteList.getQuote’;

const columns = [
{ label: ‘Quote Name’, fieldName: ‘Name’,type: ‘url’,typeAttributes: { label: { fieldName: ‘Quote Name’ },target: ‘_blank’ }} ,
{ label: ‘Quote Number’, fieldName: ‘QuoteNumber’ } ,
{ label: ‘Syncing’, fieldName: ‘IsSyncing’ },
{ label: ‘Expiration Date’, fieldName: ‘ExpirationDate’},
{ label: ‘SubTotal’, fieldName: ‘Subtotal’ },
{ label: ‘Total Price’, fieldName: ‘TotalPrice’ },
{ label: ‘Created By’, fieldName: ‘CreatedById’},
export default class Mc_QuoteList extends LightningElement {
@api recordId;
@track data;
columns = columns;
connectedCallback() {
getDetails({ oppId: this.recordId }).then(result => {
console.log(result); = JSON.parse(JSON.stringify(result));
console.log(; => {
element.Name = ‘/’+element.Id;



in the UI i am able to see the url in under the name section instead of name.

Simran January 2, 2024 - 6:30 am

the return type of apex class is list of Quote

Anjani February 19, 2024 - 3:14 pm

This is not working in Experience cloud sites, even if the xml file has correct targets provided. Is there any other way we can do it when adding the LWC in Experience cloud. Please let me know

Anjani February 20, 2024 - 6:02 am

PLease let me know if u have any way of doing this for experience cloud .


Leave a Comment