Skip to main content
added 940 characters in body
Source Link
sfdc_to_learn
  • 1.8k
  • 2
  • 39
  • 91
if (gridColumns data= )[{
    type: 'text',
    fieldName: 'Name',
    label: 'Opportunity Name'
},
{
    type: 'text',
   var tempDatafieldName: ='StageName',
 JSON   label: 'Stage'
},
{
    type: 'text',
    fieldName: 'Product2.parse(Name',
 JSON   label: 'Product Name'

},
{
    type: 'text',
    fieldName: 'Product2.stringifyFamily',
    label: 'Product Family'

}
];
gridData
allRows
@api recordId
@wire(fetchOLIs, data{ )contractId: '$recordId' });
olitreedata({ error, data }) {
    forif ( vardata i) {
  
       // this.gridData = 0;tempData;
 i < tempData     this.length;gridData i++= data.map((row) => {
 
            var consrow = tempData[{ i...row ][}; 'OpportunityLineItems'// ];copy row object
            consoleconst items = row.log('consOpportunityLineItems; '// +Save JSONitems
            delete row.stringify(OpportunityLineItems; cons// ))remove from row
            ifrow._children = items.map((item) cons=> this.flattenObject(item)); {
// flatten item
            return row;
   tempData[ i ]._children = cons;   });

    } else if ( error ) {
      


 delete tempData[ i ].OpportunityLineItems;}
}

flattenObject(object, result = {}, path = []) {
    for }(const [key, value] of Object.entries(object)) {
      if (typeof value === "object") {
        flattenObject(value, result, [...path, key]);
      } else {
        thisresult[`${path.gridDatajoin(".")}${path.length ? "." : ""}${key}`] = tempData;value;
      }
  this.allRows = tempData;}
    return result;
  }
if ( data ) {
        var tempData = JSON.parse( JSON.stringify( data ) );
        for ( var i = 0; i < tempData.length; i++ ) {
 
            var cons = tempData[ i ][ 'OpportunityLineItems' ];
            console.log('cons ' + JSON.stringify( cons ))
            if ( cons ) {

                tempData[ i ]._children = cons;
                delete tempData[ i ].OpportunityLineItems;

            }

        }
        this.gridData = tempData;
        this.allRows = tempData;
 gridColumns = [{
    type: 'text',
    fieldName: 'Name',
    label: 'Opportunity Name'
},
{
    type: 'text',
    fieldName: 'StageName',
    label: 'Stage'
},
{
    type: 'text',
    fieldName: 'Product2.Name',
    label: 'Product Name'

},
{
    type: 'text',
    fieldName: 'Product2.Family',
    label: 'Product Family'

}
];
gridData
allRows
@api recordId
@wire(fetchOLIs, { contractId: '$recordId' })
olitreedata({ error, data }) {
    if ( data ) {
  
       // this.gridData = tempData;
        this.gridData = data.map((row) => {
            row = { ...row }; // copy row object
            const items = row.OpportunityLineItems; // Save items
            delete row.OpportunityLineItems; // remove from row
            row._children = items.map((item) => this.flattenObject(item)); // flatten item
            return row;
          });

    } else if ( error ) {
      


    }
}

flattenObject(object, result = {}, path = []) {
    for (const [key, value] of Object.entries(object)) {
      if (typeof value === "object") {
        flattenObject(value, result, [...path, key]);
      } else {
        result[`${path.join(".")}${path.length ? "." : ""}${key}`] = value;
      }
    }
    return result;
  }
Source Link
sfdc_to_learn
  • 1.8k
  • 2
  • 39
  • 91

lightning tree grid issue with displaying grand child data from apex

I have this below query . Where i am trying to display Opportunity name and products associated to it in a lightning tree-grid structure.

The issue i am facing is i am able to display opportunity name . But i am unable to display product name and family

 List < Opportunity > opps = [ SELECT Id, Name, StageName,
                ( SELECT Id, Product2.Name, Product2.Family FROM OpportunityLineItems )
                FROM Opportunity WHERE Id IN:  oppsIds];

HTML -

 <lightning-tree-grid hide-checkbox-column columns={gridColumns} data={gridData} key-field="Id">
        </lightning-tree-grid>

JS -

gridColumns = [{
        type: 'text',
        fieldName: 'Name',
        label: 'Opportunity Name'
    },
    {
        type: 'text',
        fieldName: 'StageName',
        label: 'Stage'
    },
    {
        type: 'text',
        fieldName: 'Product2.Name',
        label: 'ProductName'

    },
    {
        type: 'text',
        fieldName: 'Product2.Family',
        label: 'Product Family'

    }
    ];

wire method returning the data

if ( data ) {
        var tempData = JSON.parse( JSON.stringify( data ) );
        for ( var i = 0; i < tempData.length; i++ ) {

            var cons = tempData[ i ][ 'OpportunityLineItems' ];
            console.log('cons ' + JSON.stringify( cons ))
            if ( cons ) {

                tempData[ i ]._children = cons;
                delete tempData[ i ].OpportunityLineItems;

            }

        }
        this.gridData = tempData;
        this.allRows = tempData;