UI Widgets Autocomplete

A textbox widget that supports autocompletion.

Included in: dx.phonejs.js, dx.webappjs.js, dx.all.js

The dxAutocomplete 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',
        displayExpr: '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',
        displayExpr: 'name'
    }"></div>
  • Angular
    Add a div element and apply the dx-autocomplete directive to this element.

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

Note that DevExtreme widgets require you to link the jQuery and Globalize libraries to your application. If you use the Knockout or Angular approach, the Knockout or Angular library is also required.

See Also

The dxAutocomplete 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'
    }">
        <div data-options="dxTemplate: { name: 'item' }">
            Country: <b>{{country}}</b><br/>
            <span style="color:grey;">Capital: {{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 dxAutocomplete widget.

Methods

This section describes the members used to manipulate the widget.

Events

This section describes events exposed by this widget.

Default Item Template

This section lists the data source fields that are used in a default template for auto-complete drop-down items.

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 a 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