In TreeList expanded

1 Answer 73 Views
TreeList
Premkumar
Top achievements
Rank 1
Iron
Premkumar asked on 05 Aug 2021, 03:21 PM

TreeList expanded working with "id" for expanding & collapsing. But I need use some other unique property instead of "id" for expanding & collapsing. In below example object "extension" has unique value. so how can I use "extension" for expand & collapsing.

 

employees = [
{
name: 'Daryl Sweeney',
extension: 8253,
hireDate: new Date(2012, 2, 7),
fullTime: true,
},
{
name: 'Sweeney',
extension: 8254,
hireDate: new Date(2012, 2, 7),
fullTime: false,
}
]

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 06 Aug 2021, 05:38 AM

Hello, Premkumar,

The field that will be used is part of the code in the demo, it is not hardcoded internally inside the component.

Please check how in these functions we use the id field to execute the logic. The same can be done with any field:

  const onExpandChange = (e) => {
    setState({
      ...state,
      expanded: e.value
        ? state.expanded.filter((id) => id !== e.dataItem.id) // this.state.expanded can be a collection of extension 
        : [...state.expanded, e.dataItem.id], // sam,e
    });
  };

  const handleDataStateChange = (event) => {
    setState({ ...state, dataState: event.dataState });
  };

  const addExpandField = (dataTree) => {
    const expanded = state.expanded;
    return mapTree(dataTree, subItemsField, (item) =>
      extendDataItem(item, subItemsField, {
        [expandField]: expanded.includes(item.id), // here we can check if it indludes extension 
      })
    );
  };

Regards,
Stefan
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Premkumar
Top achievements
Rank 1
Iron
commented on 06 Aug 2021, 10:11 AM

Thank you its working
Tags
TreeList
Asked by
Premkumar
Top achievements
Rank 1
Iron
Answers by
Stefan
Telerik team
Share this question
or