Drop Down List .dataItem() returns incorrect item.

7 posts, 0 answers
  1. Dimitar
    Dimitar avatar
    2 posts
    Member since:
    Mar 2012

    Posted 28 Mar 2012 Link to this post

    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
  2. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 29 Mar 2012 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Rejitha
    Rejitha avatar
    1 posts
    Member since:
    Sep 2012

    Posted 04 Sep 2012 Link to this post

    I' m getting the same issue... Can you please confirm whether this is resolved or not?

    Thanks
  5. Robert
    Robert avatar
    2 posts
    Member since:
    Aug 2014

    Posted 27 May 2015 Link to this post

    It this fixed yet? Using 2015.1.429 Mvc
  6. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 29 May 2015 Link to this post

    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!
     
  7. Robert
    Robert avatar
    1 posts
    Member since:
    Sep 2014

    Posted 20 Jul 2015 Link to this post

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

    ??

     

  8. Plamen Lazarov
    Admin
    Plamen Lazarov avatar
    135 posts

    Posted 22 Jul 2015 Link to this post

    Hello Robert,

    The observed behavior is due to a breaking change - now the optionLabel is placed as a static header on top of the pop up 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!
     
Back to Top
Kendo UI is VS 2017 Ready