[SalesForce] Record URL in lightning:datatable in Community

I am trying to create case table in Community with first column which will show Case Number and will be link to record page.

I created formula field Show_Case__c [formula: "/"&id].
Also I reference it :

 {label: 'Case Number', fieldName: 'Show_Case__c', type: 'url',sortable: true,typeAttributes: {label: { fieldName: 'CaseNumber'}}}


<aura:attribute name="columns" type="List"/>
<aura:attribute name="data" type="Object"/>

<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

<aura:if isTrue="{!not(empty(v.columns))}">
    <lightning:datatable aura:id="myTable" columns="{!v.columns}" data="{!v.data}" keyField="Id"  hideCheckboxColumn="false"  />


public static List<Case> getCases1(){
    List<Case> cases = [SELECT  Show_Case__c, Id, CaseNumber FROM Case];
    return cases;


tableset : function(component,event,helper) {

        var queryaction = component.get("c.getCases1");
         queryaction.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {


                var columns = [{label: 'Show_Case__c', fieldName: 'CaseNumber', type: 'url',sortable: true,filterable: true,typeAttributes: {label: { fieldName: 'CaseNumber'}}}];


The error which I receive is Cannot read property 'type' of undefined.

I used Hyperlink a Record in lightning:datatable for reference.

How to get this work?

I will appreciate any help. Thank you!

Best Answer

I found the way to show case number in community as link to record detail!

  1. Create Custom formula field.


LEFT($Api.Partner_Server_URL_260, FIND( '/services', $Api.Partner_Server_URL_260)) 
+ 's/detail/' + Id]
  1. Put the field in Apex SOQL query

  2. Then this code will be working

{ label: 'Case Number', fieldName: 'Show_Case__c', type: 'url', sortable: true,typeAttributes: {label:{ fieldName: 'CaseNumber'}} }