Autocomplete

A textbox widget that supports autocompletion.

Type: Object

The dxAutocomplete widget is a textbox that suggests ways to complete the text being typed. Suggestions 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 create the dxAutocomplete widget, add a div element with dxAutocomplete Knockout binding within the body of the required view.

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

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.

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.

Refer to the Add a Widget documentation section to learn how to create widgets in detail.

Show Example:
jQuery

Configuration

An object defining configuration options for the dxAutocomplete widget.

Methods

This section describes methods that can be used to manipulate a widget.

Events

This section describes events fired by this component.