1

I have this field definition in a lightning datatable:

{
  "fieldName": "Id",
  "initialWidth": "150",
  "label": "Case Number",
  "sortable": true,
  "type": "url",
  "typeAttributes": {
    "label": {
      "fieldName": "CaseNumber"
    }
  }
}

The field is shown properly, but when I click the in the link is opening this address: http://caseID with caseID the case id of the case that I'm showing.

The table is inside of a Lightning page. The same field setup is working in a Lightning component loaded in a Visual Force page.

I don't know what could be the reason. Maybe is an stupid thing. I can share my code if you want, but I'm using this code to show multiple tables but only in two of them url are shown, and it's only failing when the table is lightning UI.

2

The Salesforce Id by itself isn't a URL, and the URL type in a <lightning:dataTable> is not clever enough to realize it's been handed a record Id and handle it appropriately.

Instead, you need to generate the URL yourself and add it as a property of the line items in your source data. Your column entry will end up looking like this:

{ label: 'Case Number', 
  fieldName: 'URL', // Whatever you call this property when you load Cases (below)
  type: 'url', 
  typeAttributes: { 
   label: {
    fieldName: 'CaseNumber'
   } 
  }, 
  sortable: true 
 }

Then, when you're populating your Case data, do something like this:

cases.forEach(function(item) {
    item['URL'] = '/' + item['Id'];
}

where 'URL' is the key you've chosen to hold this data point, as above.

  • Thanks, for your answer I hoped the <lightning:datatable> smart enough for handled records ids to avoid the kind of solution that you recommend me, but finally I have to do it, thank you very much for your answer – Jesús Manuel Cantero Aug 30 '18 at 7:43

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.