AutoComplete dataItem out-by-one bug?

6 posts, 0 answers
  1. Wayne
    Wayne avatar
    24 posts
    Member since:
    Feb 2011

    Posted 28 May 2013 Link to this post

    I have objects to bind to an AutoComplete. They have Id and Name properties. I want to auto-complete on the Name and get access to the corresponding Id when an item is selected. For test purposes I'm including the Id in the string that gets bound as the Name. For test purposes I'm issuing an alert() with the details of the dataItem selected.

        @(Html.Kendo().AutoCompleteFor(model => model.SelectedItem)
            .BindTo(Model.AvailableItems.Select(x => new { x.Id, Name = string.Format("{0} ({1})", x.Name, x.Id) }))
            .DataTextField("Name")
            .Events(e => e.Select("onSelect"))
            .Filter("contains")
        )

    <script>
        function onSelect(e) {
            var dataItem = this.dataItem(e.item.index());
            alert(dataItem.Id + ":" + dataItem.Name + "(" + e.item.index() + ")");
        }
    </script>

    What I'm seeing is that in most cases (not all cases, which is even more curious to me), the Id and Name of the apparently selected dataItem don't correspond. The Id seems to (usually) be that of the NEXT item in the list after the one with the selected Name.

    Any ideas? I can try to reproduce it in a standalone sample when I get the chance..
  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 30 May 2013 Link to this post

    Hi Wayne,


    I was not able to reproduce the mentioned behavior on my side and in our Demos. As you mentioned, a small runnable project will be really helpful for us in order to investigate and fix the issue. Please send us one if it is convenient. 

    I am looking forward to hearing from you.

     

    Regards,
    Dimiter Madjarov
    Telerik
    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. Wayne
    Wayne avatar
    24 posts
    Member since:
    Feb 2011

    Posted 30 May 2013 Link to this post

    It only seems to happen with my real dataset (over 10k items). I couldn't reproduce it with a small dataset, nor with a larger dataset of 20K generated items. Attached is the sample (I had to strip out the packages and Content files to get below the upload limit). Even here, some selections are correct, most are not. I can get it to consistently fail with the search string "men", and choosing "Mendoza Prov". You'll see that the dataItem.Id is incorrect.
  5. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 03 Jun 2013 Link to this post

    Hi Wayne,


    Thank you for providing the sample project. After examine it, it turns out that the data is returned correctly from the controller. The reason for the issue is that the numbers, that are used as IDs for the items are too big and the JSON parser cannot parse them correctly. You could ensure this by running some simple tests in your browser's console. Here is a small example

    E.g.
    Number(28147497671065601)
    28147497671065600
     
    Number(28147497671065602)
    28147497671065600
     
    Number(28147497671065603)
    28147497671065604
     
    Number(28147497671065604)
    28147497671065604
     
    Number(28147497671065605)
    28147497671065604

    As a solution, you could use smaller numbers or a guid for the ID property.
    I hope that this information was helpful for you. I wish you a great day!

     

    Regards,
    Dimiter Madjarov
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Wayne
    Wayne avatar
    24 posts
    Member since:
    Feb 2011

    Posted 03 Jun 2013 Link to this post

    Wow. The ids in the database are "bigint" (C# "long"), and we can't change that. Javascript/JSON doesn't handle longs? This kinda throws our whole web development plan into the toilet...
    I guess we need to add a lot of conversion code to/from string in our ViewModels and Controllers...
  7. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 03 Jun 2013 Link to this post

    Hi Wayne,


    Sorry for this inconvenience, but the problem is indeed in the JavaScript language itself and not in the AutoComplete. Please let me know if I could assist you further.

     

    Regards,
    Dimiter Madjarov
    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