Dropdownlist setDataSource callback function needed

1 Answer 89 Views
DropDownList
Lee
Top achievements
Rank 2
Bronze
Bronze
Bronze
Lee asked on 22 Aug 2023, 02:52 PM | edited on 22 Aug 2023, 03:11 PM

I have a kendo dropdownlist with virtualization and a local array of objects used as the data source. I need to replace the datasource based on selections the user makes elsewhere on the page. The problem I'm having is that since it uses virtualization, I don't know when the datasource has finished being updated with setDataSource(newDataSource) and as such, sometimes when I try to set the new value, the new value isn't there. I don't want to use setTimeout because that is bad practice as it assumes it will take a certain amount of time to complete. The cascade event seems to only work after changing the value, not the dataSource. Is there a way to do something like this reliably: 

var newDataSourcce = getDataSource();
myDropdownList.setDataSource(newDataSource);
myDropdownList.value(100);
I can't make a dojo because the JSON object used as a datasource is too large and using a smaller array doesn't trigger the issue. Also note the getDataSource() is a function that filters the JSON object based on the other selections a user made (e.g. department: food, type: fruit, color: red; limits the list to red fruits).

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 25 Aug 2023, 12:38 PM

Hello, Lee,

A possible approach would be to use the dataBound event and a boolean as a flag. The boolean (e.g. isDataSourceReset ) would initially be false. Upon using the setDataSource method, you can switch the boolean's value to true. As the setDataSource will trigger the dataBound event, you can check if isDataSourceReset is true, and then set the new value.

Let me know how that would work for you.

Regards,
Martin
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources
Tags
DropDownList
Asked by
Lee
Top achievements
Rank 2
Bronze
Bronze
Bronze
Answers by
Martin
Telerik team
Share this question
or