Display all possibilities in dropdown

3 posts, 0 answers
  1. ping0
    ping0 avatar
    5 posts
    Member since:
    Sep 2012

    Posted 24 Oct 2012 Link to this post

    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. ping0
    ping0 avatar
    5 posts
    Member since:
    Sep 2012

    Posted 25 Oct 2012 Link to this post

    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?
  3. Kendo UI is VS 2017 Ready
  4. John
    John avatar
    17 posts
    Member since:
    Jan 2013

    Posted 26 Feb 2013 Link to this post

    THANK YOU!  You saved me a lot of time, just wanted to let you know.

    -john-
Back to Top