Lookup

A widget that allows a user to select predefined values from a lookup window.

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

The dxLookup widget allows users to select predefined values from a lookup window.

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 dxLookup widget using the Knockout approach.

HTML
<div data-bind="dxLookup:{dataSource: employees, displayExpr: 'name', valueExpr: 'id'}"></div>

The lookup items are loaded from an array specified via the dataSource configuration option. You can specify a simple array or an array of objects as the widget data source.

JavaScript
var employees = [
    { id:1, name: "Bob", hired: 2005 },
    { id:2, name: "John", hired: 2007 },
    { id:3, name: "Frank", hired: 2001 },
    { id:4, name: "Robert", hired: 2007 },
    { id:5, name: "Paul", hired: 2011 },
    { id:6, name: "Elizabeth", hired: 2000 },
    { id:7, name: "Mary", hired: 2002 },
    { id:8, name: "Michael", hired: 2003 },
    { id:9, name: "George", hired: 2002 },
    { id:10, name: "Deborah", hired: 2000 },
    { id:11, name: "Lisa", hired: 1999 },
    { id:12, name: "Mark", hired: 2011 }
];

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

  • disabled
    Specifies whether or not the lookup item is disabled.
  • visible
    Specifies whether or not the lookup 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, set 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 lookup items. For this purpose, add a div element with the data-options attribute set to dxTemplate. Provide the item name to the template. In this instance, the template will be applied automatically. See the Customize Widget Item Appearance topic to learn more about templates.

The dxLookup widget uses the byKey() method of the Store wrapped by the DataSource instance passed to the dataSource option of the widget. If you use a CustomStore, you should pass the function implementing the byKey() method to the byKey configuration option of the CustomStore.

See Also
  • To learn how to create widgets in detail, refer to the Create a Widget article.
  • The dxLookup 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 dxLookup widget.

Methods

This section describes 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 lookup 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 dxLookup 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.