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

autocomplete + ajax: How to stop client side filtering

4 Answers 401 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Kent
Top achievements
Rank 1
Kent asked on 29 Jan 2013, 03:23 PM
I have a web api for address loopup. User can type some keywords and system will search both Location Description and Address.

I managed to write the following code to make it work, well, basically.

So, whenever user types anything, application will go to server to get back results properly.
However, since I need to specify dataTextField as LocationDescription, autocomplete will always filter out results if keyword is in Address field.

Default value of filter is startsWith, I've changed it to "contains" in my code.

My question is, is there any way I can just disable client side filtering based on dataTextField?

TIA

===============
<input id="pulocation" />

<script id="template" type="text/x-kendo-tmpl">
     <b>${ data.LocationDescription }</b><br/>
     ${ data.Address } 
</script>

<script type="text/javascript">
    $(document).ready(function () {
        var myDs = new kendo.data.DataSource({
            transport: {
                read: function (options) {
                    $.ajax({
                        url: "/api/AddressLookup",
                        data: {
                            criteria: function () {
                                return $("#pulocation").val();
                            }
                        },
                        success: function (result) {
                            options.success(result);
                        },
                        dataType: "json",
                        beforeSend: function (xhr) {
   // set auth info
                        }
                    });
                }
            }
        });

        $("#pulocation").kendoAutoComplete({
            minLength: 1,
            dataTextField: "LocationDescription",
            template: kendo.template($("#template").html()),
            filter: "contains", // <--
            dataSource: myDs
        });

        $("#pulocation").data("kendoAutoComplete").list.width(400);

        $("#pulocation").keydown(function (e) {
                myDs.read();    
        });
    });
</script>

4 Answers, 1 is accepted

Sort by
0
Kent
Top achievements
Rank 1
answered on 29 Jan 2013, 05:06 PM
I just found another user asked the same question. 
http://www.kendoui.com/forums/ui/autocomplete/filtering-on-more-than-one-data-field.aspx

He switched to jquery UI autocomplete though.

I actually tried jquery UI autocomplete first, but I want to use kendo web UI for consistency (we are paid customer). 

Is there any solution or workaround?

Thanks~

0
Kent
Top achievements
Rank 1
answered on 29 Jan 2013, 07:09 PM
Currently I'm 'overriding' kendo.data.DataSource.filter method, but I think it's like hack lol...
0
Accepted
Georgi Krustev
Telerik team
answered on 30 Jan 2013, 09:12 AM
Hello Kent,

 
I will suggest you enable serverFiltering option. Thus widget will show the data as it is returned from the server.

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
Kent
Top achievements
Rank 1
answered on 30 Jan 2013, 02:44 PM
Thanks Georgi, that works!
Tags
AutoComplete
Asked by
Kent
Top achievements
Rank 1
Answers by
Kent
Top achievements
Rank 1
Georgi Krustev
Telerik team
Share this question
or