This is a migrated thread and some comments may be shown as answers.

JSON DataSource adds dropdown for children even if 0 items

3 Answers 59 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 01 Apr 2014, 11:34 PM
When setting the PanelBar dataSource property, it adds a dropdown (ie a HasChildren indicator) even if there are no items in the array.
Would this be a reasonable change request to make - to not do this?

Basically if you do this
 items: [
                            {
                                text: "Sub Sub Item 1",
                                value: "Sub Sub Item 1 Value",
                                items: []
                            },

You can test this by modifying the code as above on this fiddler.
http://jsfiddle.net/bundyo/WM4VG/light/

This is quite a pain, in my case, as I'm populating the dataSource from a C# DTO object. I have "items" as a property and cannot easily just "remove" it. Nor should I need to, in my opinion.

3 Answers, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 03 Apr 2014, 12:26 PM
Hello Peter,

Thank you for contacting us.

Changing this functionality will be considered a breaking change, as a lof of the Kendo UI users, are relaying to this functionality of the PanelBar control, so changing this default behavior will create a lot of inconvenience for other users.

I would suggest you to check our uservoice section and post your suggestion there, so other people from the community can vote for it, and if it gets popular we will see it implemented in the future.

A workaround would be to manually walk through the PanelBar with jQuery and detect if you have not child items, then you can hide the node.

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Peter
Top achievements
Rank 1
answered on 03 Apr 2014, 11:02 PM
Right.

I must admit, my mind boggles why it would be implemented like this in the first place - it would never occur to me to rely on the "presence" of an array and ignore that the array is empty. 

It may be a breaking change to fix it, but it should never had been designed that way, in my opinion.

If anyone else is reading this... here's my coffeescript to work around it - pass your datasource array into this method before giving to PamelBar.

removeEmptyItems = (array) ->
_(array).each (d) ->
delete d.items if d.items?.length is 0
removeEmptyItems d.items
return array
0
Kiril Nikolov
Telerik team
answered on 04 Apr 2014, 08:33 AM
Hello Peter,

Thank you very much for your input and provided workaround. 

We will keep in mind your suggestion for future implementations.

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
PanelBar
Asked by
Peter
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Peter
Top achievements
Rank 1
Share this question
or