6

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".

1 Answer 1

4

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.

3
  • Huh, interesting. I've had a hard time finding good documentation on columns in general, and mostly relied on examples instead.
    – Adrian Larson
    Commented May 22, 2019 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
    Commented May 22, 2019 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
    Commented May 22, 2019 at 22:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .