2

My application built with AngularJs and KendoUI controls. I used AutoComplete Text Box so many places in the application. Now client wants that search should be with "Contains" filter. for the same i need to put filter: 'contains' everywhere AutoComplete control used.

I want to change default filter 'startWith' to 'contains' at beginning of the application. So that i can escape to make change every html file.

can anyone knows how to do the same?

Snehal
  • 1,070
  • 12
  • 20

2 Answers2

1

I guess you need to update your auto complete filter property at least once for all controls to support dynamic property binding and bind to some root configuration, like:

<input kendo-auto-complete k-filter="config.autoComplete.defaultFilter" />

So will be able to change default filter in future by updating only config value.

Another approach - is to override default "setOptions" behavior for "AutoComplete" component to use correct filter by default somewhere on app start:

var nativeSetOptions = window.kendo.ui.AutoComplete.prototype.setOptions;

window.kendo.ui.AutoComplete.prototype.setOptions = function(options) {
  options.filter = 'contains';
  nativeSetOptions.call(this, options);      
}
VadimB
  • 5,533
  • 2
  • 34
  • 48
  • I am looking for second approach where overriding default filter. I written code which you given at beginning of one of the JS file but its not working for me. – Snehal Oct 09 '17 at 09:10
  • Can you set debugger into this part? Is it executed when you open page with some autoComplete inside? – VadimB Oct 09 '17 at 09:29
  • Thanks Friend... Its worked for me. I added following line. Please correct me if you find anything wrong in that. window.kendo.ui.AutoComplete.prototype.options.filter = "contains"; – Snehal Oct 09 '17 at 09:38
1

You can use k-options attribute:

<input kendo-auto-complete ng-model="yourModel" k-data-source="yourDataSource" style="width: 100%;" k-options="autocompleteOptions"/>

and then in your controller:

$scope.autocompleteOptions = {
   filter:"contains"
}
Ruben Lopez
  • 704
  • 7
  • 18