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

AutoComplete dataItem out-by-one bug?

5 Answers 58 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Wayne
Top achievements
Rank 1
Wayne asked on 28 May 2013, 08:33 PM
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..

5 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 30 May 2013, 11:45 AM
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!
0
Wayne
Top achievements
Rank 1
answered on 30 May 2013, 01:02 PM
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.
0
Dimiter Madjarov
Telerik team
answered on 03 Jun 2013, 11:37 AM
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!
0
Wayne
Top achievements
Rank 1
answered on 03 Jun 2013, 12:29 PM
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...
0
Dimiter Madjarov
Telerik team
answered on 03 Jun 2013, 02:58 PM
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!
Tags
AutoComplete
Asked by
Wayne
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Wayne
Top achievements
Rank 1
Share this question
or