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
Phuc Nguyen 18Phuc Nguyen 18 

LWC tree grid more than 2 levels

Hello,
I have a LWC tree grid that shows the aprent and child records.  How can I expand this to the grandchild records?
Thanks,
Best Answer chosen by Phuc Nguyen 18
ANUTEJANUTEJ (Salesforce Developers) 
Hi Phuc,

As mentioned in the documentation example there is an implementation of tree grid up to 3 levels can you try checking it once:

>> https://developer.salesforce.com/docs/component-library/bundle/lightning:treeGrid/example#lightningcomponentdemo:exampleTreeGridBase

Let me know in case if there are any questions or in case if this comes handy can you please choose this as the best answer so that it can be used by others in the future.

Regards,
Anutej

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi Phuc,

As mentioned in the documentation example there is an implementation of tree grid up to 3 levels can you try checking it once:

>> https://developer.salesforce.com/docs/component-library/bundle/lightning:treeGrid/example#lightningcomponentdemo:exampleTreeGridBase

Let me know in case if there are any questions or in case if this comes handy can you please choose this as the best answer so that it can be used by others in the future.

Regards,
Anutej
This was selected as the best answer
Phuc Nguyen 18Phuc Nguyen 18
Hey Anutej,
Thank you for the reply.  I looked at that example before but they are hard coding the values.
I need to pull them from a controller and populate.  I am going to try to change my query to include attachments
Select Id,Name, Directory__c,Folder_Template__c,Parent_File_Folder__c,(Select Id,Name, Directory__c,
         Folder_Template__c,Parent_File_Folder__c FROM Sub_Contractor__r WHERE Parent_File_Folder__c != null ORDER BY Parent_File_Folder__c Nulls First)
         FROM Contractor__c  WHERE Parent_File_Folder__c = null AND  File_Folder__c.Directory__r.Directory_Template__r.Active__c = true 
         ]
 
gridData;
    
    @track gridData;
    @track error;
    @track gridColumns = [{
        type: 'text',
        fieldName: 'Name',
        label: 'Folders'
     },
     {
         type: 'button',
         typeAttributes: {
             label: 'View'
         }
    }];
  

    @wire(fetchfolders)  
    folderTreeData({ error, data }) {

        if (data) {

            if (data) {
                let parseData = JSON.parse(JSON.stringify(data));
    
                for (let i = 0; i < parseData.length; i++) {
                    parseData[i]._children = parseData[i]['Sub_Contract__r'];
                    delete parseData[i]['Sub_Contract__r'];
                }
    
                this.gridData = parseData;
            } else if (error) {
                console.log('error ====> ' + JSON.stringify(error));
            }
        }
    }