0

I am unable to get the amount field to display, even though I have used type = 'currency' in @track columns[], and the amount exists in the record on backend. Here is a screenshot of the output: enter image description here

<template>
  <lightning-card title="Payables Grid">
    <br />
    <div style="width: auto;">
      <template if:true={payments}> 
          <lightning-datatable data={payments}
                               columns={columns}
                               key-field="Id"
                               onsort={updateColumnSorting}
                               sorted-by={sortedBy}
                               sorted-direction={sortedDirection}>
          </lightning-datatable>
      </template>
    </div>
  </lightning-card>
</template>
/* eslint-disable no-console */
import { LightningElement, wire, track } from 'lwc';

// importing apex class methods
import fetchPaymentsforAgents from '@salesforce/apex/KI_PayablesGridController.fetchPaymentsTable';

export default class PayablesGrid2 extends LightningElement {
    //reactive variables
    // datatable columns with row actions
    @track columns = [
        {
            label: 'Payment Number',
            fieldName: 'Name',
            type: 'text',
            sortable: true
        }, {
            label: 'Amount',
            fieldName: 'Amount_to_pay__c',
            type: 'currency',
            sortable: true
        }, {
            label: 'Carrier',
            fieldName: 'Payment_Policy_Carrier__c',
            type: 'text',
            sortable: true
        }, {
            label: 'Effective Date',
            fieldName: 'Payment_Policy_Effective_Date__c',
            type: 'text',
            sortable: true
        }, {
            label: 'Received Date',
            fieldName: 'Payment_Transaction_Date__c',
            type: 'text',
            sortable: true
        }, {
            label: 'Policy Holder',
            fieldName: 'Payment_Policy_Insured_Name__c',
            type: 'text',
            sortable: true
        }, {
            label: 'Policy Number',
            fieldName: 'Payment_Policy_Name__c',
            type: 'text',
            sortable: true
        }
    ];

    @track error;
    @track payments = [];
    @track sortedBy;
    @track sortDirection = 'asc';

    //retrieving agent payment information using wire service
    @wire(fetchPaymentsforAgents)
    wiredPayments({error,data}) {
        if (data) {
            this.payments = data;
        } else if (error) {
            this.error = error;
        }
    }

    sortData(fieldName, direction) {
        //serialize the data before calling sort function
        var parseData = JSON.parse(JSON.stringify(this.payments));

        //return the value stored in the field
        var keyValue = (a) => a[fieldName];

        //checking reverse direction
        var isReverse = direction === 'asc' ? 1: -1;

        //sorting data
        parseData.sort((a,b) => {
            let x = keyValue(a) ? keyValue(a).toLowerCase() : ''; //handling null values
            let y = keyValue(b) ? keyValue(b).toLowerCase() : '';

            //sorting values based on direction
            return isReverse * ((x > y) - (y > x));
        });

        //set sorted data to data table data
        this.payments = parseData;
    }

    updateColumnSorting(event) {
        //field name
        this.sortedBy = event.detail.fieldName;

        //sort direction
        this.sortDirection = event.detail.sortDirection;

        //calling sortData function to sort data based on direction and selected field
        this.sortData(this.sortedBy, this.sortedDirection);
    }
}
4
  • Are you getting currency field using JSON.parse(JSON.stringify(this.payments))? Oct 11, 2019 at 15:57
  • I tried using console.log on parseData, I just get the output as : this.payments: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object] I am new to LWC development. I'm not sure how exactly to debug the issue. Oct 11, 2019 at 16:30
  • for console simply do JSON.stringify(this.payments) and not parse it. Oct 11, 2019 at 16:38
  • Yes, it prints the amount. Below is a portion of the output: ****JSON.stringify(this.payments): [{"Id":"a0fS000000509VVIAY","Name":"P-000000993","Amount_to_Pay__c":149.99,"To_pay__c":"001S0000013LQA2IAO","Payment_Policy_Carrier__c":"Humana","Payment_Policy_Effective_Date__c":"2019-01-27","Payment_Policy_Insured_Name__c":......................... Oct 11, 2019 at 17:59

1 Answer 1

1
{
        label: 'Amount',
        fieldName: 'Amount_to_Pay__c',
        type: 'currency',
        sortable: true
}

API name incorrect (Capital P)

1
  • Thank you so much, it worked! I didn't think it would be case sensitive. Apex isn't case sensitive, so it didn't strike me at all! Oct 12, 2019 at 12:36

You must log in to answer this question.

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