You need to sign in to do that
Don't have an account?
Aditi Mohanty 5
Name and price of the products is not showing in datatable, but soql is executing successfully. What to do?
data is not showing in lightning component
global with sharing class products { @AuraEnabled public static List<PricebookEntry> getproduct() { List<PricebookEntry> prod= [SELECT Product2.Name, Unitprice FROM PricebookEntry]; return prod; } } component-- <aura:component controller="products" > <aura:attribute name="productname" type="PricebookEntry[]"/> <aura:attribute name="cols" type="List"/> <aura:handler name="init" value="{!this}" action="{!c.doinit}"/> <lightning:datatable data="{!v.productname}" columns="{!v.cols}" keyField="Id" onrowaction="{!c.onRowAction}"/> </aura:component> controller--- ({ doinit : function(component) { component.set( 'v.cols' , [ { 'label': 'Name', 'fieldName': 'Name', 'type': 'text' }, {label': 'Price', 'fieldName': 'Price', 'type': 'Currency' }, { 'label': 'Action', 'type': 'button', 'typeAttributes': { 'label': 'Add to Cart', 'name': 'view_details' } }, { 'label': 'Action', 'type': 'button', 'typeAttributes': { 'label': 'Buy', 'name': 'view_details' } } ]); var action = component.get("c.getproduct"); // var self = this; action.setCallback(this, function(actionResult) { var state = actionResult.getState(); if (state === "SUCCESS") { component.set("v.productname", actionResult.getReturnValue()); component.set("v.productprice",actionResult.getReturnValue()); } }); $A.enqueueAction(action); }, })
Name and price of the products is not showing in datatable, but soql is executing successfully. What to do?
I found two mistake in your code:
- You are using UnitPrice field in soql but you are binding wrong field name('Price')
- You are using parent field in lightning data table. Lightning Data table does not support parent fields . You need to create a column dynamically in the returned list.
I did some minor tweaks in controller jsLet us know if you still cannot see the columns. Hope this helps!
All Answers
Please see the example in the documentation for the exact syntax
Let me know if this helps, if it does, please mark this answer as best so that others facing the same issue will find this information useful. Thank you
It is working for product2.obj not for pricebookEntry.
I found two mistake in your code:
- You are using UnitPrice field in soql but you are binding wrong field name('Price')
- You are using parent field in lightning data table. Lightning Data table does not support parent fields . You need to create a column dynamically in the returned list.
I did some minor tweaks in controller jsLet us know if you still cannot see the columns. Hope this helps!