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

[Solved] Custom Filter

1 Answer 77 Views
AutoCompleteBox for HTML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Heinrich
Top achievements
Rank 1
Heinrich asked on 18 Feb 2014, 04:43 AM
Hi

Is it possible to specify a custom filter function?. I need to filter based on multiple fields of the objects.

Thank you

1 Answer, 1 is accepted

Sort by
0
Martin Yankov
Telerik team
answered on 18 Feb 2014, 11:54 AM
Hello Heinrich,

Currently the AutoCompleteBox control allows filtering only by a single field. To accomplish your task you can merge the different fields into a single one with a separator and use the "contains" filter operation.
var array = [
    { title: "Football", host: "USA" },
    { title: "Basketball", host: "Canada" },
    { title: "Hokey", host: "Russia" }
];
 
for (var i = 0; i < array.length; i++) {
    array[i].searchField = array[i].title + " " + array[i].host;
}
 
var autoComplete = new Telerik.UI.RadAutoCompleteBox(document.getElementById("autoCompleteBox"), {
    dataSource: {
        data: array
    },
    dataTextField: "searchField",
    filter: "contains"
});

You can then use templates to display the item in the dropdown list properly.

I hope this information is useful. Let me know in case you need further assistance or have questions.

Regards,
Martin Yankov
Telerik

Check out the new Telerik Platform - the only modular platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native apps. Register for the free online keynote and webinar to learn more about the Platform on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT).

Tags
AutoCompleteBox for HTML
Asked by
Heinrich
Top achievements
Rank 1
Answers by
Martin Yankov
Telerik team
Share this question
or