5 Answers, 1 is accepted
To get the correct result when you use the dataSource.get function you must define which field should be used as the identifier of the items so then it searches for an item which id field has the value you pass to the get function.
To do so:
$(
'#MyDropDownControlID'
).kendoDropDownList({
dataSource: {
transport: {
read:
"url"
},
schema: {
model: {
id:
'IdField'
}
}
},
dataValueField:
'ValueField'
,
dataTextField:
'TextField'
});
After that if you use dataSource.get(whatever) you will get the item data.
I am encountering the same problem. I am trying to access the datasource bound to a dropdownbox, from another dropdownbox. Is this not possible? I have tried for example
var test = $("#NameInput").data("kendoDropDownList").dataSource;
console.log(test.getByUid("DepartmentNo").get(14683));
Gives
jQuery.Deferred exception: Cannot read property 'get' of undefined TypeError: Cannot read property 'get' of undefined
From what I can see from the documentation, this is correct, so what could I be doing wrong?
Hello, Stephen,
Thank you for your question.
There are two things to keep in mind when using the DataSource.get() method.
- The get method requires the schema.model option to be set and the id of the model to be specified.
- If you are loading the data from a remote dataSource the get method may be called before there is a response to the read request. Consequently the method will return undefined. To resolve this await the response before calling the get method.
This Dojo showcases how to define the schema.model and a possible approach on getting a dataSource dataItem after a set amount of time.
Regards,
Stoyan
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hi Stoyan. Thanks for the reply. I should have posted again to say I fixed the issue. It was indeed that the data request was not received and thus not yet bound. I handled it by using the dataBound: event to execute the functions that weren't working.
Best Regards
STeve
Hi, Steve,
It is great to hear that you have solved the issue.
Thank you for sharing your solution with the community.
Regards,
Stoyan
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.