Last Updated: 25 Jul 2022 11:31 by ADMIN
Michael D
Created on: 05 Jul 2022 14:48
Category: DropDownList
Type: Bug Report
DropDownList setOptions() leads to incorrectly dataBound() event objects

In our application, we have the requirement to display the DropDownList's filter textBox only if there are more than a specific number of items in the DropDownList. Therefore, we count the items everytime they change (i.e. an item is added/removed or perhaps all items are replaced) and then update the DropDownList's filter setting accordingly via setOptions().

Additionally, we use the dataBound() event for internal UI tweaks and therefore access the e.sender object.

This DOJO demonstrates that e.sender has a different structure before and after setOptions() is called. For instance, the list property does no longer exist. Check the console output, the event object is logged every time dataBound() is called.

Interestingly, this only happens when passing a complete (but updated) object to setOptions() and not when passing only a partial options object. Still, re-setting options to the same value as before should not interfere with any event args.

Veselin Tsvetanov
Posted on: 25 Jul 2022 11:31

Hi Michael,

I must agree that the setOptions() method description needs improvement, so that it explains the cases in which manual rebind of events is needed. That is why I have logged an item for documentation improvement.

 As a small token of gratitude for suggestion the above I have updated your Telerik points.

Veselin Tsvetanov
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.

Michael D
Posted on: 20 Jul 2022 07:26

Thank you for the clarification. Maybe it should somehow be mentioned in the documentation that you need to rebind manually?

Especially since the documentation states

In some cases, the setOptions method can recreate and rebind the widget instance.

which implies that a rebind would happen automatically and that's the caveat. In this case, however, a developer needs be careful because a rebind does not take place.

Veselin Tsvetanov
Posted on: 12 Jul 2022 10:20

Hi Michael,

The issue observed is caused by the fact that the dataBound event handler is reassigned to the DropDownList widget instance. In order to keep event calls and their arguments in order, please remove all handlers from the options object:

delete updatedOptions.dataBound

If you still need to re-assign an event handler you should do it using unbind() and bind() method calls:

dropDownList.bind("dataBound", function(e) {

Here is a modified version of the sample discussed implementing the above suggestion:

I hope that the above explains the case. If you have any other questions, please do not hesitate to contact us.

Veselin Tsvetanov
Progress Telerik

The Premier Dev Conference is back! 

Coming to you live from Progress360 in-person or on your own time, DevReach for all. Register Today.