You need to sign in to do that
Don't have an account?
Yuki Tan
my datatable rows show null
Hi, i write a code about datatable and apex, but the result is null.
I have a custome object called Warehouse.It have a relationship field, related to Product object. And a number filed called Amount.
want to show they in datatable. Now page show null but amount of records is right. And i try to show Name,Type__c , they will show. Just Product__r.Name and Amount__c is null.
Im sure that my SOQL is right.because i run it in develope consle query editor.
This is my code.
cmp:
I have a custome object called Warehouse.It have a relationship field, related to Product object. And a number filed called Amount.
want to show they in datatable. Now page show null but amount of records is right. And i try to show Name,Type__c , they will show. Just Product__r.Name and Amount__c is null.
Im sure that my SOQL is right.because i run it in develope consle query editor.
This is my code.
cmp:
<aura:handler name="init" value="{!this}" action="{!c.doInit}" /> <aura:attribute name="columns" type="List"/> <aura:attribute name="data" type="Object"/> <aura:attribute name="errors" type="Object" default="[]"/> <lightning:card title="Pending QA"> <lightning:datatable columns="{! v.columns }" data="{! v.data }" keyField="Id" errors="{! v.errors}" hideCheckboxColumn="true"/> </lightning:card>controller:
doInit : function(component, event, helper) { component.set('v.columns', [ { label: 'Product', fieldName: 'Product__r.Name', type: 'text',editable:false}, { label: 'Amount', fieldName: 'Amount__c', type: 'text',editable:false}]); helper.getPendingRecord(component,event,helper); }Helper:
getPendingRecord : function(component, event, helper) { var action = component.get("c.query"); // call back action.setCallback(this, function(response){ var state = response.getState(); // call back success if (state == "SUCCESS"){ var result = response.getReturnValue(); component.set('v.data', result); } // call back failed else { var toastEvent=$A.get("e.force:showToast"); toastEvent.setParams({ "title":'Error!', "message":'Get Record Failed!', "duration":5000, "type":ERROR }); toastEvent.fire(); } }); $A.enqueueAction(action); }class:
public static List<Warehouse__c> query() { List<Warehouse__c> pending = new List<Warehouse__c>(); pending = [SELECT Product__r.Name,Amount__c FROM Warehouse__c WHERE Type__c = 'pendingArea']; return pending; }Pls help me. Thanks!
Lightning datatable will not support the display of parent object field data's in Table . Simply Relationship Queries will not work directly in Lightning datatable. So you can only display the Warehouse__c object fields. Display the Product__C field will work but Product__r.Name.
This is in Ideas : https://success.salesforce.com/ideaView?id=0873A000000EA7VQAW
SO we have some workaround for this:
1. By Using Flattener in JS Controller:
https://developer.salesforce.com/forums/?id=9062I000000IJzvQAG
https://developer.salesforce.com/forums/?id=9062I000000XtwnQAC
https://iwritecrappycode.wordpress.com/2017/11/22/salesforce-lightning-datatable-query-flattener/
https://www.wissel.net/blog/2018/08/lightning-datatables-and-relationship-queries.html
2. Using the Wrapper Class in Apex controller instead of normal Sobject List return:
https://developer.salesforce.com/forums/?id=9060G0000005V95QAE
Thanks,
Maharajan.C
All Answers
But the product name still is null.
The product filed of Warehouse__c is custome filed. And the product object is a standard object. Name filed of product obj is also a standard field.
Lightning datatable will not support the display of parent object field data's in Table . Simply Relationship Queries will not work directly in Lightning datatable. So you can only display the Warehouse__c object fields. Display the Product__C field will work but Product__r.Name.
This is in Ideas : https://success.salesforce.com/ideaView?id=0873A000000EA7VQAW
SO we have some workaround for this:
1. By Using Flattener in JS Controller:
https://developer.salesforce.com/forums/?id=9062I000000IJzvQAG
https://developer.salesforce.com/forums/?id=9062I000000XtwnQAC
https://iwritecrappycode.wordpress.com/2017/11/22/salesforce-lightning-datatable-query-flattener/
https://www.wissel.net/blog/2018/08/lightning-datatables-and-relationship-queries.html
2. Using the Wrapper Class in Apex controller instead of normal Sobject List return:
https://developer.salesforce.com/forums/?id=9060G0000005V95QAE
Thanks,
Maharajan.C