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

Drop Down List .dataItem() returns incorrect item.

6 Answers 1320 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Dimitar
Top achievements
Rank 1
Dimitar asked on 29 Mar 2012, 04:57 AM
I have a dropdownlist with an option label and a number of items. When I use list.dataItem() it seems to return the next index, not the currently selected index.

This problem seems only to occur when an optionLabel is used and can be reproduced in the cascading drop down list demo in the following way.

Place a break point at the bottom of the categories change function:

$("#categories").kendoDropDownList({
    optionLabel: "Select category...",
    dataTextField: "CategoryName",
    dataValueField: "CategoryID",
    dataSource: {
        type: "odata",
        serverFiltering: true,
        transport: {
            read: "http://demos.kendoui.com/service/Northwind.svc/Categories"
        }
    },
    change: function () {
        var value = this.value();
        if (value) {
            productsDataSource.filter({
                field: "CategoryID",
                operator: "eq",
                value: parseInt(value)
            });
            products.enable();
        } else {
            products.enable(false);
        }
        products.select(0);
        orders.select(0);
        orders.enable(false); <--- BREAK HERE
    }
}); 

Then select an item in the categories drop down, such as, confections. When the break point is hit, add a watch to $('#categories').data('kendoDropDownList').dataItem();

It is expected that the dataItem will be confections, but it is actually Diary Products.

Thanks

6 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 29 Mar 2012, 09:17 AM
Hello Dimitar,

 
Thank you for drawing our attention to this issue. It seams that the problem occurs only when the optionLabel is defined. We will fix this for the next official release of KendoUI. Paid customers can download the next internal build. As a gratitude for your involvement I have updated your Telerik points.

As a workaround you can get the raw data record using this code snippet:

onChange: function() {
    //get correct dataitem
    var index = this.selectedIndex,
           dataItem;
 
    if (this.options.optionLabel && index > 0) {
          index = index - 1;
    }
    dataItem = this.dataItem(index);
}

Regards,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Rejitha
Top achievements
Rank 1
answered on 04 Sep 2012, 10:16 AM
I' m getting the same issue... Can you please confirm whether this is resolved or not?

Thanks
0
Robert
Top achievements
Rank 1
answered on 27 May 2015, 06:19 AM
It this fixed yet? Using 2015.1.429 Mvc
0
Georgi Krustev
Telerik team
answered on 29 May 2015, 11:09 AM
Hello Robert,

Yes, the dataItem method works as expected in 2015.1.429 release. Note that you will need to pass the correct index in order to get the corresponding data item.

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Robert
Top achievements
Rank 1
answered on 20 Jul 2015, 03:18 PM

I have exactly the same problem.

After updating to 2015.2.624, i get always the previous entry​ with:

 onChange: function(e) {

                  var dataItem = this.dataItem(e.item.index());​

...

Only, if I use the optionlabel.

Without Optionlabel, it works like befor.

If I turn back to the old version, the code is working again.​

??

 

0
Plamen Lazarov
Telerik team
answered on 22 Jul 2015, 03:19 PM

Hello

The observed behavior is due to a breaking change - now the optionLabel is placed as a static header on top of the element. In order to get the correct item remove .index() from your code.  

var dataItem = this.dataItem(e.item)

 

Regards,
Plamen Lazarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
DropDownList
Asked by
Dimitar
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Rejitha
Top achievements
Rank 1
Robert
Top achievements
Rank 1
Robert
Top achievements
Rank 1
Plamen Lazarov
Telerik team
Share this question
or