4

I am using a <lightning:datatable> to display some data in a Quick Action. It works great, and I was able to get the table to display the name of a parent record as a link using a column definition looking like:

columns = [{
    label: "Parent",
    fieldName: "ParentLink",
    type: "url",
    typeAttributes: {
        label: {
            fieldName: ParentName
        }
    }
}, {
    ...
}]

And in my callback for the server function which retrieves the record, I have some code looking like:

const records = response.getReturnValue();
records.forEach(function (record) {
    record.ParentLink = "/" + record.ParentId,
    record.ParentName = record.Parent.Name
});

Functionally, this approach does everything we need, but the user experience is not optimal. The anchor tag which gets rendered on the page looks like:

<a href="/parentId" title="/parentId" target="_blank">ParentName</a>

Is there any way I can control the title and target attributes? The latter is the major problem, because opening the record in a new tab is antithetical to the navigation paradigm in Lightning Experience. Given that it is a Quick Action modal, I would prefer it to be target="_top".

2

The typeAttributes for a url field accepts an additional parameter, target, which carries through to the generated <a> tag.

It's documented in the Lightning Component Library, but only in passing:

TYPE  DESCRIPTION                                 SUPPORTED TYPE ATTRIBUTES
url   Displays a URL using lightning:formattedUrl label, target, tooltip

I've applied it successfully with, e.g.,

typeAttributes: { 
    label: {
        fieldName: 'CaseNumber'
    },
    target: '_self'
},

in the past, which works well for in-page links in Console applications.

Similarly, tooltip maps to title.

| improve this answer | |
  • Huh, interesting. I've had a hard time finding good documentation on columns in general, and mostly relied on examples instead. – Adrian Larson May 22 '19 at 22:15
  • The tooltip attribute does indeed control title, and works the same way as label in that you can specify fieldName. Thanks for the quick response! I'm using target: "_top", but that's the only difference. – Adrian Larson May 22 '19 at 22:18
  • It's odd that target => target but tooltip => title. I've never used that one before so tried it in a demo project. – David Reed May 22 '19 at 22: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.