UI Widgets Autocomplete

A textbox widget that supports autocompletion.

Included in: dx.mobile.js, dx.web.js, dx.viz-web.js, dx.all.js
Module: ui/autocomplete
Autocomplete interactive configuration
Copy code
$("#autocomplete").dxAutocomplete({
});

The Autocomplete widget is a textbox that suggests ways of completing the text being typed.

You can create a widget using one of the following approaches.

  • jQuery
    Use the dxAutocomplete jQuery plug-in.

    HTML
    <div id="autoComplete"></div>
    JavaScript
    $("#actionSheet").dxAutocomplete({
        dataSource: autoCompleteData,
        placeholder: 'Type country name',
        valueExpr: 'name'
    });
  • Knockout
    Add a div element and apply the dxAutocomplete binding to this element.

    HTML
    <div data-bind="dxAutocomplete: {
        dataSource: autoCompleteData,
        placeholder: 'Type country name',
        valueExpr: 'name'
    }"></div>
  • AngularJS
    Add a div element and apply the dx-autocomplete directive to this element.

    HTML
    <div dx-autocomplete="{
        dataSource: autoCompleteData,
        placeholder: 'Type country name',
        valueExpr: 'name'
    }"></div>

Note that DevExtreme widgets require you to link the jQuery library to your application. If you use the Knockout or AngularJS approach, the Knockout or AngularJS library is also required. For detailed information on linking these libraries to your project, refer to the Installation article.

The Autocomplete widget supports common Collection Container and Editor widget functionality. You can find detailed information on principles of working with the widget in the dxAutocomplete section of the Editor Widgets article. For the information on using Collection Container functionality refer to the Collection Container Widgets guide.

View Demo

Show Example:
AngularJS
Knockout
jQuery
<div ng-controller="demoController">
    <div class="autocomplete" dx-autocomplete="{
        dataSource: autocompleteDataSource,
        displayExpr: 'country',
        placeholder: 'Type country name',
        itemTemplate: 'item'
    }" dx-item-alias="itemObj">
        <div data-options="dxTemplate: { name: 'item' }">
            Country: <b>{{itemObj.country}}</b><br />
            <span style="color:grey;">Capital: {{itemObj.capital}}</span>
        </div>
    </div>
</div>
var myApp = angular.module('myApp', ['dx']);
myApp.controller("demoController", function ($scope) {
    $scope.autocompleteDataSource = new DevExpress.data.DataSource([]);
    //Loads json data and passes it to the DataSource
    $.get("/Content/data/countries.txt", function (data) {
        for (var i = 0; i < data.length; i++) {
            $scope.autocompleteDataSource.store().insert(data[i]);
        }
        $scope.autocompleteDataSource.load();
    }, "json");
});
angular.element(document).ready(function () {
    angular.bootstrap(document, ['myApp']);
});
body{
    text-align: center;
}
.autocomplete{
    margin: 10px;
}
<div class="autocomplete" data-bind="dxAutocomplete: {
    dataSource: autocompleteDataSource,
    displayExpr: 'country',
    placeholder: 'Type country name',
    itemTemplate: 'item'
}">
    <div data-options="dxTemplate: { name: 'item' }">
        Country: <b data-bind="text: country"></b><br />
        <span style="color:grey;">Capital: <span data-bind="text: capital"></span></span>
    </div>
</div>
var myViewModel = {
    autocompleteDataSource: new DevExpress.data.DataSource([])
}
ko.applyBindings(myViewModel);
//Loads json data and passes it to the DataSource
$.get("/Content/data/countries.txt", function (data) {
    for (var i = 0; i < data.length; i++) {
        myViewModel.autocompleteDataSource.store().insert(data[i]);
    }
    myViewModel.autocompleteDataSource.load();
}, "json");
body{
    text-align: center;
}
.autocomplete{
    margin: 10px;
}
<div class="autocomplete" id="myAutocomplete"></div>
var autocompleteData = new DevExpress.data.DataSource([]);
$("#myAutocomplete").dxAutocomplete({
    dataSource: autocompleteData,
    displayExpr: 'country',
    placeholder: 'Type country name',
    itemTemplate: function (itemData, itemIndex, itemElement) {
        itemElement.append("Country: <b>" + itemData.country + "</b><br/>\
        <span style=\"color:grey;\">Capital: " + itemData.capital + "</span>");
    }
});
//Loads json data and passes it to the DataSource
$.get("/Content/data/countries.txt", function (data) {
    for (var i = 0; i < data.length; i++) {
        autocompleteData.store().insert(data[i]);
    }
    autocompleteData.load();
}, "json");
body{
    text-align: center;
}
.autocomplete{
    margin: 10px;
}

Configuration

An object defining configuration options for the Autocomplete widget.

Methods

This section describes the members used to manipulate the widget.

Events

This section describes events fired by this widget.

Default Item Template

This section lists the data source fields that are used in a default item template.

By default, a predefined item template is applied to display the items of this widget. This template is based on certain fields of the data source provided for this widget. Below is the list of these fields. If the default item template is not appropriate for your task, implement a custom item template based on these or other fields of your data source.

See Also