Activity › Forums › Salesforce® Discussions › What is the use of lightning:treeGrid in lightning component in Salesforce?
Tagged: Account Hierarchy, Forecasting, JS Controller, Lightning Tree, Salesforce Lightning Component
-
What is the use of lightning:treeGrid in lightning component in Salesforce?
Posted by Deepak on September 3, 2019 at 1:24 PMWhat is the use of lightning:tree Grid in lightning component in salesforce?
Achintya replied 6 years, 8 months ago 4 Members · 3 Replies -
3 Replies
-
Hi,
A lightning:treeGrid in lightning component displays hierarchical data in a table
- [adinserter block='9']
-
Hi Deepak,
A lightning:treeGrid component displays hierarchical data in a table. Its appearance resembles lightning:datatable, with the exception that each row can be expanded to reveal a nested group of items. Rows that contain nested data display a chevron icon to denote that they can be expanded or collapsed. This visual representation is useful for displaying structured data such as account hierarchy or forecasting data. Each column can be displayed based on the data type. For example, a phone number is displayed as a hyperlink with the tel: URL scheme by specifying the phone type.
-
Lightning:treeGrid component displays hierarchical data in a table. Its appearance resembles lightning: data table, with the exception that each row can be expanded to reveal a nested group of items. Rows that contain nested data display a chevron icon to denote that they can be expanded or collapsed. Each column can be displayed based on the data type. Here is an example of lightning:datatable.
Apex Controller:
public class SampleAuraController { @AuraEnabled public static List <Account> getAccountList() { List<Account> accList = new List<Account>(); accList = [SELECT Id, Name, NumberOfEmployees, Phone, (SELECT FirstName, LastName, Email FROM Contacts) FROM Account LIMIT 10]; return accList; } }Lightning Component:
<aura:component controller="SampleAuraController" implements="flexipage:availableForAllPageTypes" access="global"> <aura:attribute type="Account[]" name="acctList"/> <aura:attribute name="gridColumns" type="List" /> <aura:attribute name="gridData" type="Object" /> <aura:attribute name="gridExpandedRows" type="Object" /> <aura:handler name="init" value="{!this}" action="{!c.doInit}"/> <div class="slds-m-around_xx-large"> <lightning:treeGrid aura:id="accTree" columns="{!v.gridColumns}" data="{!v.gridData}" keyField="Id"/> </div> </aura:component>Lightning Component JS Controller:
({ doInit : function(component, event, helper) { var columns = [ { type: 'text', fieldName: 'Name', label: 'Account Name' }, { type: 'number', fieldName: 'NumberOfEmployees', label: 'Employees' }, { type: 'phone', fieldName: 'Phone', label: 'Phone Number' }, { type: 'text', fieldName: 'FirstName', label: 'First Name' }, { type: 'text', fieldName: 'LastName', label: 'Last Name' }, { type: 'email', fieldName: 'Email', label: 'Email' } ]; component.set('v.gridColumns', columns); var action = component.get("c.getAccountList"); action.setCallback(this, function(response){ var state = response.getState(); if (state === "SUCCESS" ) { var resultData = response.getReturnValue(); for (var i=0; i<resultData.length; i++ ) { resultData[i]._children = resultData[i]['Contacts']; delete resultData[i].Contacts; } component.set('v.gridData', resultData); } }); $A.enqueueAction(action); } })
Log In to reply.