Enabling single selection mode on the Kendo UI TreeView

1 Answer 55 Views
TreeView
Klaus
Top achievements
Rank 1
Klaus asked on 07 Dec 2024, 08:23 PM

Hello, I am trying to enable single selection mode on the Kendo UI TreeView and update the styling of each node as the item is selected. However, I am running into a few challenges. I am working in TypeScript. I have looked at all the examples and while simple, they simple do not work as listed unless I am missing something. 

My TreeView is configured like this:

const [selectedLayer, setSelectedLayer] = useState(['']);
const OnLayerItemSelected = (event: TreeViewItemClickEvent) => {

const selectedItemId = String(event.item.id);
setSelectedLayer([ids]);

const item = event.item;
item.selected = !item.selected;

// other code

}

 

<TreeView
className={"margin-top-5 margin-left-minus-2p5em"}
data={nonContextualWorkspaceGroups}
item={(props) =>
_CustomNonContextualLegendItemRenderer({
...props,
onCheckChange: onLayerVisibilityChanged,
})}
selectField={"selected"}
draggable={true}
expandIcons={false}
checkboxes={false}

aria-multiselectable = {false}
onExpandChange={onLayerExpansionChanged}
onCheckChange={onLayerVisibilityChanged}
onItemClick={OnLayerItemSelected}
/>

With the above code, my application crashes with this error:

If I instead do this pasted below, the application does not crash but single select mode is not enabled and a selected node in the tree looks like this:

 



const [selectedLayer, setSelectedLayer] = useState({
ids: ["100"],
idField : "id"
});


const OnLayerItemSelected = (event: TreeViewItemClickEvent) => {

const selectedItemId = String(event.item.id);
setSelectedLayer({ids : [selectedItemId], idField:'id'});

const item = event.item;
item.selected = !item.selected;

// other code

}

<TreeView
className={"margin-top-5 margin-left-minus-2p5em"}
data={processTreeViewItems(nonContextualWorkspaceGroups, {
select: selectedLayer,
//check: visibleLayers,
//expand: expandedWorkspace,
})}
item={(props) =>
_CustomNonContextualLegendItemRenderer({
...props,
onCheckChange: onLayerVisibilityChanged,
})}
selectField={"selected"}
draggable={true}
expandIcons={false}
checkboxes={false}

aria-multiselectable = {false}
onExpandChange={onLayerExpansionChanged}
onCheckChange={onLayerVisibilityChanged}
onItemClick={OnLayerItemSelected}
/>

1 Answer, 1 is accepted

Sort by
0
Yanko
Telerik team
answered on 10 Dec 2024, 09:00 PM

Hello, Klaus,

Thank you for the provided screenshots. I tried reproducing the error displayed in the picture but to no avail.

Can you provide a runnable StackBlitz example or a demo project that reproduces the error so I can further test and debug it, to figure out the root of the issues and prepare a solution for you?

I appreciate your understanding and patience and await your response.

Regards,
Yanko
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.

Tags
TreeView
Asked by
Klaus
Top achievements
Rank 1
Answers by
Yanko
Telerik team
Share this question
or