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;
});
}
}
Add a comment
|
1 Answer
I recollect that including an empty (or non-empty) children array keeps the chevron:
_children: []
whereas having no _children property means no chevron.
-
it doesn't work when i remove the []Noha– Noha2023-03-08 21:48:46 +00:00Commented Mar 8, 2023 at 21:48
-
Hi @Noha, You need to not set the
_childrenproperty at all. If you have not set it then I'm wrong. (Setting the property to e.g.nullis still having the property set.)Keith C– Keith C2023-03-09 00:09:35 +00:00Commented Mar 9, 2023 at 0:09 -
