You need to sign in to do that
Don't have an account?
VSK98
Unable to display the data in Lightning:treeGrid
Hi All,
I am unable to display the records using Lightning:treeGrid. The data has passing from apex controller to JS Controller but data not displayed.
Was anything missed over there?
LightningComponent:
JS Controller:
Apex Classes:
Regards,
VSK98
I am unable to display the records using Lightning:treeGrid. The data has passing from apex controller to JS Controller but data not displayed.
Was anything missed over there?
LightningComponent:
<aura:component implements="force:appHostable" controller="Nested_JSONController"> <aura:attribute name="gridColumns" type="List" /> <aura:attribute name="gridData" type="Object" /> <aura:handler name="init" value="{!this}" action="{!c.onLoad}"/> <lightning:treeGrid columns="{! v.gridColumns }" data="{! v.gridData }" keyField="Id" aura:id="mytree" /> </aura:component>
JS Controller:
({ onLoad : function(component, event, helper) { var columns = [ { type: 'double', fieldName: 'totalPrice', label: 'totalPrice' }, { type: 'datetime', fieldName: 'statementDate', label: 'statementDate' }, { type: 'double', fieldName: 'unitPrice', label: 'unitPrice' }, { type: 'double', fieldName: 'quantity', label: 'quantity' }, ]; component.set('v.gridColumns', columns); var action = component.get("c.Nested_JSON"); action.setCallback(this, function(response){ var state = response.getState(); if ( state === "SUCCESS" ) { alert(state); var data = response.getReturnValue(); console.log(data); component.set('v.gridData', data); } }); $A.enqueueAction(action); } })
Apex Classes:
public class InvoiceWrapper_L { public class LineItem { @AuraEnabled public Double unitPrice {get; set;} @AuraEnabled public Double quantity {get; set;} @AuraEnabled public String productName {get; set;} public Double getLineItemTotal() { return this.unitPrice * this.quantity; } } public class Invoice { @AuraEnabled public Double totalPrice {get; set;} @AuraEnabled public DateTime statementDate {get; set;} @AuraEnabled public String contactnumber {get; set;} @AuraEnabled public List<LineItem> lineItems {get; set;} @AuraEnabled public Integer invoiceNumber {get; set;} } @AuraEnabled public List<Invoice> invoiceList {get; set;} }
public class Nested_JSONController { @AuraEnabled public static InvoiceWrapper_L Nested_JSON() { InvoiceWrapper_L wrapper ; Http h = new Http(); HttpRequest request = new HttpRequest(); request.setEndPoint('https://docsample.herokuapp.com/jsonSample'); request.setHeader('Content-type', 'application/json'); request.setMethod('GET'); HttpResponse response = h.send(request); wrapper = (InvoiceWrapper_L) JSON.deserializeStrict(response.getBody(), InvoiceWrapper_L.class); system.debug('@@@@@'+wrapper); return wrapper; } }
Regards,
VSK98
Thanks for your response !!
I have changed the code as you said above. Still, the issue persists. Regards,
VSK98
Refer this link
https://rajvakati.com/2018/04/15/usage-of-lightningtreegrid/