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

why doesn't $('#MyDropDownControlID').data("kendoDropDownList").dataSource.get(1) work?

5 Answers 593 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Stanley
Top achievements
Rank 1
Stanley asked on 01 Oct 2012, 03:38 PM
All it ever returns for me is an 'undefined' on a kendo.dropdownlist which clearly has multiple items in its content.  

5 Answers, 1 is accepted

Sort by
0
Nohinn
Top achievements
Rank 1
answered on 02 Oct 2012, 08:58 AM
Have you set the id of the model?
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.
0
Stephen
Top achievements
Rank 1
answered on 22 Feb 2021, 11:48 AM

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?

 

 

 

 

 

 

0
Stoyan
Telerik team
answered on 25 Feb 2021, 11:45 AM

Hello, Stephen,
Thank you for your question.

There are two things to keep in mind when using the DataSource.get() method.

  1. The get method requires the schema.model option to be set and the id of the model to be specified.
  2. 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/.

0
Stephen
Top achievements
Rank 1
answered on 25 Feb 2021, 11:49 AM

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

0
Stoyan
Telerik team
answered on 26 Feb 2021, 03:41 PM

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/.

Tags
DropDownList
Asked by
Stanley
Top achievements
Rank 1
Answers by
Nohinn
Top achievements
Rank 1
Stephen
Top achievements
Rank 1
Stoyan
Telerik team
Share this question
or