I am creating a datatable in a LWC and I cannot figure out why the data is not rendering!
HTML
<template>
<template if:true={openCases}>
<lightning-datatable
data={openCases}
columns={casesColumns}
key-field='Id'>
</lightning-datatable>
</template>
</template>
Javascript
import { LightningElement , api , track, wire} from 'lwc';
import getOpenCases from '@salesforce/apex/ACG_FSL_OpenViolationCasesController.getOpenCases';
const casesColumns = [
{label: 'Case', fieldname: 'FSL_In_Jeopardy_Reason__c', type: 'text'},
{label: 'Owner', fieldname: 'OwnerName', type: 'text'},
{label: 'Call Id', fieldname: 'Call_Id__c', type: 'text'}
];
export default class ACG_FSL_OpenViolationsCasesLWC extends LightningElement {
@api recordId;
@track openCases = undefined;
@track myCases;
@track error;
casesColumns = casesColumns;
@wire(getOpenCases, { CaseId : '$recordId' })
wiredCases({ error, data }){
if(data){
const tempcasesList = [];
data.forEach(c => {
const tempFSL_In_Jeopardy_Reason__c = (typeof c.FSL_In_Jeopardy_Reason__c === 'undefined') ? 'null' : c.FSL_In_Jeopardy_Reason__c;
const tempCall_Id__c = (typeof c.Call_Id__c === 'undefined') ? 'null' : c.Call_Id__c;
const tempcase = {Id: c.Id,
FSL_In_Jeopardy_Reason__c: tempFSL_In_Jeopardy_Reason__c,
OwnerName: c.Owner.Name,
Call_Id__c: tempCall_Id__c};
console.log(tempcase);
tempcasesList.push(tempcase);
})
this.openCases = tempcasesList;
}
else if (error){
this.error = error;
}
}
}
APEX
public with sharing class ACG_FSL_OpenViolationCasesController {
@AuraEnabled(cacheable=true)
public static list<case> getOpenCases(String CaseId){
Case currentcase = [select id, FSL_Service_Appointment_Territory__c from case where id = :CaseId];
List<case> openCases = new list<case>();
openCases = [Select Id, FSL_Service_Appointment_Territory__c, ownerid, Owner.Name, Call_Id__c, FSL_In_Jeopardy_Reason__c FROM case
WHERE FSL_Service_Appointment_Territory__c = :currentcase.FSL_Service_Appointment_Territory__c AND isClosed = false];
return openCases;
}
}