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

Display all possibilities in dropdown

2 Answers 460 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
ping0
Top achievements
Rank 1
ping0 asked on 24 Oct 2012, 01:58 PM
Hello.

I need to make the dropdown of autocomplete display all items listed in the datasource. I have found the .search() method and it almost does what I want, the only problem is that it requires me to pass it at least one character and does not appear to work  if I specify an empty string. 

How would I get all items to show?

Here is a jsfiddle that illustrates what I'm trying to do...
http://jsfiddle.net/3j2GP/1/

2 Answers, 1 is accepted

Sort by
0
ping0
Top achievements
Rank 1
answered on 25 Oct 2012, 08:34 AM
I've got it working by modifying the source (see bold code): 

/**
* Filters dataSource using the provided parameter and rebinds drop-down list.
* @param {string} word The filter value.
* @example
* // get a reference to the autocomplete widget
* var autocomplete = $("autocomplete").data("kendoAutoComplete");
*
* // Searches for item which has "Inception" in the name.
* autocomplete.search("Inception");
*/
search: function (word) {
    var that = this,
    options = that.options,
    ignoreCase = options.ignoreCase,
    separator = options.separator,
    length;
 
    word = word || that.value();
 
    that._current = null;
 
    clearTimeout(that._typing);
 
    if (separator) {
        word = wordAtCaret(caretPosition(that.element[0]), word, separator);
    }
 
    length = word.length;
 
    if (!length && !length == 0) {
        that.popup.close();
    } else if (length >= that.options.minLength) {
        that._open = true;
 
        that.dataSource.filter({
            value: ignoreCase ? word.toLowerCase() : word,
            operator: options.filter,
            field: options.dataTextField,
            ignoreCase: ignoreCase
        });
    }
},


And then setting minLength to 0 on initialization:

var autocomplete = $("#autocomplete").kendoAutoComplete({
    suggest: true,
    dataSource: items,
    dataTextField: "Name",
      minLength : 0     
}).data("kendoAutoComplete");


This seems to work fine for me but I do not know all the implications of this hack, is there a better way?
0
John
Top achievements
Rank 2
answered on 26 Feb 2013, 08:20 PM
THANK YOU!  You saved me a lot of time, just wanted to let you know.

-john-
Tags
AutoComplete
Asked by
ping0
Top achievements
Rank 1
Answers by
ping0
Top achievements
Rank 1
John
Top achievements
Rank 2
Share this question
or