[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'}}}

Component

<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"  />
</aura:if>

Apex

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

JavaScript

tableset : function(component,event,helper) {

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

                component.set('v.data',response.getReturnValue());

                var columns = [{label: 'Show_Case__c', fieldName: 'CaseNumber', type: 'url',sortable: true,filterable: true,typeAttributes: {label: { fieldName: 'CaseNumber'}}}];
                component.set('v.columns',columns);
            }


        });
        $A.enqueueAction(queryaction); 
    }, 

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.

Formula:

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'}} }