function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PACO_DPACO_D 

render threw an error in 'lightning:treeGrid' [can't convert undefined to object]

Hello  I am trying using lightning:treeGrid  and i am facing this issue render threw an error in 'lightning:treeGrid' [can't convert undefined to object]

my component
<aura:component controller="Milestone" implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" 
                access="global" >

    <aura:attribute name="gridCol" type="List" />
    <aura:attribute name="gridData" type="Object" />
    
    <aura:handler name="init" value="{!this}" action="{!c.doInitTree}"/>

    <lightning:treeGrid columns="{!v.gridCol}"
        data="{!v.gridData}"
        keyField="id"
        aura:id="mytree"
    />
</aura:component>
my Js Controller
 
public class Milestone {

    @AuraEnabled
    public static list<Stage__mdt> getlistTreeGrid(){
       list<Stage__mdt> listvaleur=new list<Stage__mdt>([SELECT  Label,IsSelect__c,(SELECT Label, IsSelect__c  FROM Jalons__r) FROM Stage__mdt]);
        return listvaleur;
    }

}
my apex controller
 
public class Milestone {

    @AuraEnabled
    public static list<Stage__mdt> getlistTreeGrid(){
       list<Stage__mdt> listvaleur=new list<Stage__mdt>([SELECT  Label,IsSelect__c,(SELECT Label, IsSelect__c  FROM Jalons__r) FROM Stage__mdt]);
        return listvaleur;
    }

}

the error screenshot

User-added image

what is the mistake ?


 
kajal rathodkajal rathod
Can u update the correct js controller of your's
PACO_DPACO_D
my js controller
 
({
    doInitTree: function(component, event, helper) {
        var callApexCtrl = component.get('c.getlistTreeGrid');
        callApexCtrl.setCallback(
            this,
            function(response){
                var state = response.getState();
                if(component.isValid()&&state==="SUCCESS"){
                    var tree =response.getReturnValue();
                    var obj=[];
                    //Change "Contacts" key to "_children"
                for(var i=0; i<tree.length;i++) {
                    tree[i]._children = tree[i]['Jalons__r'];
                    delete tree[i].Jalons__r; 

                }
                    var columns = [
                        {
                            type: 'text',
                            fieldName: 'Label',
                            label: 'stage'
                        }
                    ];
                    component.set("v.gridCol", columns);
                    component.set("v.gridData", tree);
                    
                }
                
            }
            
        );
        $A.enqueueAction(callApexCtrl);
    }
})