rinku
7/31/2019 - 11:57 PM

lwc


<template>
    <lightning-tree-grid data={gridData} columns={gridColumns} key-field= 'id'>

    </lightning-tree-grid>
</template>

/*
* Author: Sravya Reddy Lingam
*
* Date Created: 2019/06/20
*
* Description: This Js is used to create a tree view for Sub Assemblies and its related specifications
*
* Copyright 2019 Specright. All rights reserved
*/

/* eslint-disable no-undef */
/* eslint-disable vars-on-top */
/* eslint-disable no-console */
import { LightningElement, wire, track, api } from 'lwc';
import getSubAssemblyTreeGrid from '@salesforce/apex/SubAssemblyTreeGridviewController.getSubAssemblyTreeGrid';
const columns = [
  {
      type: 'url',
      fieldName: 'link',
      label: 'SubAssemblies',
      initialWidth: 350,
      typeAttributes: {
          label: {fieldName : 'name'}
      }
  },
  {
      type: 'text',
      fieldName: 'description',
      initialWidth: 200,
      label: 'Description'
  },
  {
      type: 'text',
      fieldName: 'recordType',
      initialWidth: 180,
      label: 'Record Type'
  },
  {
      type: 'text',
      fieldName: 'quantity',
      label: 'Quantity'
  },
  {
      type: 'text',
      fieldName: 'type',
      label: 'Type'
  }
];
//console.log("SubassemblyId",subAssemblyId);
export default class SubAssemblyTreeGridview extends LightningElement {

  @api subAssemblyId;
  @track gridColumns;
  @track gridData;
  @track error;

  gridColumns = columns;
  @wire(getSubAssemblyTreeGrid, {subAssemblyId : '$subAssemblyId'})
  wiredData({error, data}) {
      if (data) {
          data = data.replace(/children/g, "_children");
          console.log("String data @@@@", data);
          console.log("data @@@@", JSON.parse(data));

          this.gridData = JSON.parse(data);
      }

      if (error) {
          this.error = error;
          console.log("error @@@@", JSON.stringify(this.error));
      }
   }
}



<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="subAssemblyTreeGridView">
    <apiVersion>46.0</apiVersion>
    <isExposed>true</isExposed>
</LightningComponentBundle>