Is it possible to show a data tree structure with Autocomplete?

1 Answer 722 Views
DropDownList TreeView
Dide
Top achievements
Rank 2
Iron
Iron
Dide asked on 24 Oct 2022, 01:25 PM

The AutoComplete component is exactly what I need, with it being an input field offering suggestions based on the typed text. However, I have a nested data structure like

const nestedData = [
{
text: 'Furniture',
items: [{ text: 'Tables & Chairs' }, { text: 'Sofas' }, { text: 'Occasional Furniture' }],
},
{
text: 'Decor',
items: [{ text: 'Bed Linen' }, { text: 'Curtains & Blinds' }, { text: 'Carpets' }],
},
];

 

Is it possible to show this? Maybe using the DropdownTree or TreeView component with `itemRender`?

Dide
Top achievements
Rank 2
Iron
Iron
commented on 25 Oct 2022, 02:49 PM

Actually I will have 3 levels of nested data:


const nestedData = [
{
text: 'Furniture',
items: [{ text: 'Tables & Chairs', items: [{text: 'Pilows'}] }, { text: 'Sofas', items: [{text: 'Blankets'}] }, { text: 'Occasional Furniture' }],
},
{
text: 'Decor',
items: [{ text: 'Bed Linen', items: [{text: 'Rugs'}] }, { text: 'Curtains & Blinds' }, { text: 'Carpets' }],
},
];

1 Answer, 1 is accepted

Sort by
0
Accepted
Konstantin Dikov
Telerik team
answered on 26 Oct 2022, 05:23 AM

Hello Dide,

The AutoComplete component works with flat data only, so in order to use it you can flat the data prior to binding it to the component.

If you want to keep the hierarchical structure you can use a DropDownTree with filtering and maybe expand all items:

And here is one way of expanding all items initially (the second one is to add "expanded: true" to all items):

Hope this helps.

 

Regards,
Konstantin Dikov
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
DropDownList TreeView
Asked by
Dide
Top achievements
Rank 2
Iron
Iron
Answers by
Konstantin Dikov
Telerik team
Share this question
or