1

I am trying to make the 'Name' field clickable in a community and having some trouble getting it point to a url.

I am following this thread:

Hyperlink record name LWC datatable

It seems like the updated solution does not require a wrapper class here so I thought it would be easy to implement. I am sure I am missing something on my end. It does not seem like I am getting anything in the row.id.

Here's the code:

import { LightningElement, wire, track, api } from 'lwc';
import StatementOfValuesDataFeed from '@salesforce/apex/StatementOfValuesDataFeed.getOldAssetValues';
import { updateRecord } from 'lightning/uiRecordApi';
import { refreshApex } from '@salesforce/apex';
import { showToastEvent } from 'lightning/platformShowToastEvent';
import getOldAssetValues from '@salesforce/apex/StatementOfValuesDataFeed.getOldAssetValues';

const COLS = [
    {label: 'Asset Value', fieldName:'nameUrl', editable: false, sortable: true, type: 'url', typeAttributes: {label: { fieldName:'Name', target: '_blank'}}},
    {label: 'Asset Name', fieldName:'Asset_Name__c', editable: false, sortable: true},
    {label: 'Asset Type', fieldName:'Asset_Type__c', editable: false, sortable: true},
    {label: 'Agency Owner Name', fieldName:'Agency_Owner__c', editable: false, sortable: true},
    {label: 'Owner Type', fieldName:'Agency_Owner_Type__c', editable: false, sortable: true},
    {label: 'Premium Net', fieldName:'Net_Premium_Number__c', editable: false, sortable: true},
    {label: 'Invoice Amount', fieldName:'Invoice_AV__c', editable: false, sortable: true},
    {label: 'System Id', fieldName:'Asset_System_ID__c', editable: false, sortable: true},
];

export default class StatementOfValuesAssetTable extends LightningElement {

    @track error;
    @track columns = COLS;
    @track oldAssets = [];

    @wire(getOldAssetValues)

    wiredAssets(result) {
        const { data, error } = result;
        if (data) {
            let nameUrl;
            this.oldAssets = data.map(row => {
                nameUrl = `/${row.id}`;
                return {...row , nameUrl}
            })
            this.error = null;
        }
        if(error) {
            this.error = error;
            this.oldAssets = [];
        }
    }
}

and

<template>
    <lightning-card title = "SOVAssetTable" icon-name="custom:custom63">

        <div class="slds-m-around_medium">
            <template if:true={oldAssets}>
                <lightning-datatable
                    key-field="Id"
                    data={oldAssets}
                    columns={columns}
                    draft-values={draftValues}
                    hide-checkbox-column="true">
                </lightning-datatable>
            </template>
            <template if:true={oldAssets.error}>
                <!--- error handling save-->
            </template>
        </div>
    </lightning-card>
</template>

Any help on how to get my row.id into the url would be superb.

Thanks, B

1
  • Check in the @wire, you have row.id not row.Id Javascript is case-sensitive, so that might be your issue – stackasaur Jan 3 '20 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.