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 to complete the text being typed.

This widget, like any other DevExtreme UI widget, can be created using one of three possible approaches: jQuery, Knockout or AngularJS. The following code demonstrates how to create the dxAutocomplete widget using the Knockout approach.

HTML
<div data-bind="dxAutocomplete: { dataSource: autocompleteData, displayExpr: 'country' }">

Suggestions for the entered text are loaded from an array specified via the dataSource configuration option. You can specify a DataSource object, a simple array, or an array of objects as the widget data source.

JavaScript
var autocompleteData = [
    { country: "Australia", capital: "Canberra" },
    { country: "Brasilia", capital: "Brasilia" },
    { country: "Congo", capital: "Brazzaville" },
    { country: "Egypt", capital: "Kair" },
    { country: "Estonia", capital: "Talinn" },
    { country: "France", capital: "Paris" },
    { country: "Germany", capital: "Berlin" },
    { country: "Italy", capital: "Rome" },
    { country: "Netherlands", capital: "Amsterdam" },
    { country: "Russian Federation", capital: "Moscow" },
    { country: "Ukraine", capital: "Kiev" },
    { country: "United kingdom", capital: "London" },
    { country: "USA", capital: "Washington" }
];

To display widget items, a default template is applied based on the following fields of the data source item objects.

  • disabled
    Specifies whether or not the widget item is disabled.
  • visible
    Specifies whether or not the widget item is visible.
  • html
    Specifies the HTML code inserted into the item element.
  • text
    Specifies the text inserted into the item element.

To learn more about the fields used in the default item template, refer to the Default Item Template reference section of the widget.

If there is no text field in the data source objects, assign another data source field to the displayExpr configuration option to enable a user to select the required object by the value of this field.

You can introduce a custom template for the widget's items. For this purpose, add a div element with the data-options attribute set to dxTemplate. Assign item to the template name. In this instance, the template will be applied automatically. See the Customize Widget Item Appearance topic to learn more about templates.

See Also
  • To learn how to create widgets in detail, refer to the Create a Widget article.
  • The dxAutocomplete widget is related to the Collection Containers and Editors categories. Read an overview of the features that are common for collection container widgets in the Common Tasks topic of the Collection Containers article. To learn about the features that are typical for editors, refer to the Common Tasks topic of the Editors article.
Show Example:
jQuery

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 fired by this component.

Default Item Template

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

By default, a predefined item template is applied to display items of DevExtreme collection widgets. This template is based on certain fields of the data source provided for a widget. Below is the list of the fields that take part in a default item template for the dxAutocomplete widget. 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. For details refer to the Customize Widget Item Appearance topic.