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
VSK98VSK98 

How can we display the nested JSON values in lightning:treegrid

Hi All,

How can we display the nested JSON values in lightning:treegrid. I am getting values from Apex to lightning when I checked the console. 
Please find the attached screenshot.
User-added image
Column names:
component.set('v.tablecolumns', [
                {label: 'Group name', fieldName: 'group_name', type: 'text'},
            	{label: 'GroupId', fieldName: 'groupid', type: 'number'},
            	{label: 'CustomerId ', fieldName: 'Subcustomer.CustomerId ', type: 'text'},
                {label: 'Name', fieldName: 'CustomerName ', type: 'url',
                typeAttributes: {label: { fieldName: 'CustomerName' }, target: '_blank'}},
                {label: 'Street', fieldName: 'Subcustomer__r.Street', type: 'text'},
                {label: 'City', fieldName: 'City', type: 'text'},
        		{label: 'Post Code', fieldName: 'postalcode', type: 'text'},
        		{label: 'Country', fieldName: 'Country', type: 'text'},
       		    {label: 'No of Assets', fieldName: 'Assetcnt', type: 'text'},
            	
            ]);

I have tried with Subcustomer__r & Subcustomer. also but no results.

Regards,
VSK98
Raj VakatiRaj Vakati
Refer this link  i have shown how to do it for account and contacts .. same like how you want here

https://rajvakati.com/2018/04/15/usage-of-lightningtreegrid/

 
Raj VakatiRaj Vakati
Json fomrate must be like this for nested ones
 
var nestedData = [
            {
                "name": "123555",
                "accountName": "Rewis Inc",
                "employees": 3100,
                "phone": "837-555-1212",
                "accountOwner": "http://example.com/jane-doe",
                "accountOwnerName": "Jane Doe",
                "billingCity": "Phoeniz, AZ"
            },

            {
                "name": "123556",
                "accountName": "Acme Corporation",
                "employees": 10000,
                "phone": "837-555-1212",
                "accountOwner": "http://example.com/john-doe",
                "accountOwnerName": "John Doe",
                "billingCity": "San Francisco, CA",
                "_children": [
                    {
                        "name": "123556-A",
                        "accountName": "Acme Corporation (Bay Area)",
                        "employees": 3000,
                        "phone": "837-555-1212",
                        "accountOwner": "http://example.com/john-doe",
                        "accountOwnerName": "John Doe",
                        "billingCity": "New York, NY",
                        "_children": [
                            {
                                "name": "123556-A-A",
                                "accountName": "Acme Corporation (Oakland)",
                                "employees": 745,
                                "phone": "837-555-1212",
                                "accountOwner": "http://example.com/john-doe",
                                "accountOwnerName": "John Doe",
                                "billingCity": "New York, NY"
                            },
                            {
                                "name": "123556-A-B",
                                "accountName": "Acme Corporation (San Francisco)",
                                "employees": 578,
                                "phone": "837-555-1212",
                                "accountOwner": "http://example.com/jane-doe",
                                "accountOwnerName": "Jane Doe",
                                "billingCity": "Los Angeles, CA"
                            }
                        ]
                    },

 
VSK98VSK98
Hi Raj,

I am getting the format as same but the field names are different in each table. In your code, the fields names are same.

Regards,
VSK98
Jun JoseJun Jose
@VSK98

Lightning tree grid inherits from Lightning data table which has a limitation of accessing flattened data. In other words the dot notation doesnt work on lightning data table. You can't do a 'foo.bar.zz' to access the value. See this link (https://salesforce.stackexchange.com/questions/193273/winter-18-lightningdatatable-does-not-get-values-from-a-parent-record).