1

enter image description hereJS file

import { LightningElement, wire , track} from "lwc";
import { NavigationMixin } from 'lightning/navigation';
import { refreshApex } from '@salesforce/apex';

// Import the schema
import Name from "@salesforce/schema/User.Name";

import getAllTopManagers from "@salesforce/apex/ManagersHierarchy.getAllTopManagers";
import getManagers from "@salesforce/apex/ManagersHierarchy.getManagers";

const actions = 
 [
  { label: 'Edit', name: 'edit_record'}
 ];

const COLS = 
[
{fieldName: "Name", label: "Name", editable: true, hideDefaultActions: true},
{fieldName:"Weight__c", label:"Weight", editable: true, hideDefaultActions: true},
{type: 'action', label: '', typeAttributes: { rowActions: actions, menuAlignment: 
'right' }}
];



export default class WeightedRR extends NavigationMixin(LightningElement)
 {
gridColumns = COLS;
isLoading = true;
gridData = [];


@wire(getAllTopManagers)
parentAccounts({ error, data }) {
    if (error) {
        console.error("error loading Users", error);
    } else if (data) {
        this.gridData = data.map((user) => ({
            _children: [],
            ...user
        }));
        this.isLoading = false;
        
    }
}

handleOnToggle(event) {

    const rowName = event.detail.name;

    if (!event.detail.hasChildrenContent && event.detail.isExpanded) {
        this.isLoading = true;
        getManagers({parentId: event.detail.name})
            .then((result) => {
            
                if (result && result.length > 0) {
                    const newChildren = result.map((child) => ({
                        _children: [],
                        ...child
                    }));
                    this.gridData = this.getNewDataWithChildren(event.detail.name, 
    this.gridData,newChildren);
                } 
            })

            .finally(() => {
                this.isLoading = false;
            });

    }
}

getNewDataWithChildren(rowName, data, children) {

    return data.map((row) => {
        let hasChildrenContent = false;
        if (
            Object.prototype.hasOwnProperty.call(row, "_children") &&
            Array.isArray(row._children) &&
            row._children.length > 0
        ) {
            hasChildrenContent = true;
        }

        if (row.Id === rowName) {
            row._children = children;
        } else if (hasChildrenContent) {
            this.getNewDataWithChildren(rowName, row._children, children);
        }
        return row;
    });
 }
}

1 Answer 1

1

I recollect that including an empty (or non-empty) children array keeps the chevron:

_children: []

whereas having no _children property means no chevron.

3
  • it doesn't work when i remove the [] Commented Mar 8, 2023 at 21:48
  • Hi @Noha, You need to not set the _children property at all. If you have not set it then I'm wrong. (Setting the property to e.g. null is still having the property set.) Commented Mar 9, 2023 at 0:09
  • Thank you so much it worked. Commented Mar 9, 2023 at 0:31

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.