UI Widgets 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.

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

  • jQuery
    Use the dxLookup jQuery plug-in.

    HTML
    <div id="lookup"></div>
    JavaScript
    $("#lookup").dxLookup({
        dataSource: lookupData,
        displayExpr: 'name',
        title: 'Lookup title',
        searchEnabled: true
    });
  • Knockout
    Add a div element and apply the dxLookup binding to this element.

    HTML
    <div data-bind="dxLookup: {
        dataSource: lookupData,
        displayExpr: 'name',
        title: 'Lookup title',
        searchEnabled: true
    }"></div>
  • Angular
    Add a div element and apply the dx-lookup directive to this element.

    HTML
    <div dx-lookup="{
        dataSource: lookupData,
        displayExpr: 'name',
        title: 'Lookup title',
        searchEnabled: true
    }"></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 dxLookup widget supports common Collection Container, Editor, and Overlay widget functionality. Refer to the Collection Container Widgets, Editor Widgets and Overlay Widgets articles for details on using common functions. For detailed information on working with the dxLookup widget, refer to the dxLookup guide.

View Demo

Show Example:
AngularJS
Knockout
jQuery
<div ng-controller="demoController">
    <div class="lookup" dx-lookup="{
        dataSource: lookupDataSource,
        displayExpr: 'name',
        valueExpr: 'this',
        pagingEnabled: false,
        title: 'States',
        onValueChanged: updateStateInfo
    }"></div>
    <div class="info dx-state-invisible">
        <div class="info-image">
            <img style="margin:5px;" ng-attr-src="{{imagePath}}"/>
        </div>
        <div class="info-name">
            <b style="text-align:center; font-size:larger;" >{{name}}</b>
        </div>
        <p>Capital: <i>{{capital}}</i></p>
        <p>Population: <i>{{population}}</i></p>
        <p>Area: <i>{{area}}</i></p>
    </div>
</div>
var myApp = angular.module('myApp', ['dx']);
myApp.controller("demoController", function ($scope) {
    $scope.name = "none";
    $scope.capital = "none";
    $scope.area = "none";
    $scope.population = "none";
    $scope.imagePath = "";
    $scope.updateStateInfo = function (e) {
        $(".info.dx-state-invisible").removeClass("dx-state-invisible");
        $scope.name = e.value.name;
        $scope.capital = e.value.capital;
        $scope.area = e.value.area;
        $scope.population = e.value.population;
        $scope.imagePath = e.value.imagePath;
    };
    $scope.lookupDataSource = new DevExpress.data.DataSource({
        store: [],
        paginate: false,
        map: function (dataItem) {
            dataItem.imagePath = "/Content/images/doc/15_1/PhoneJS/flags/" + dataItem.name.replace(" ", "") + ".gif";
            return dataItem;
        }
    });
    $.get("/Content/data/states.txt", function (data) {
        for (var i = 0; i < data.length; i++) {
            $scope.lookupDataSource.store().insert(data[i]);
        }
        $scope.lookupDataSource.load();
    }, "json");
});
angular.element(document).ready(function () {
    angular.bootstrap(document, ['myApp']);
});
.lookup{
    margin: 10px;
}
.info {
    margin: 10px;
    padding: 10px;
    border: solid 1px blue;
    background: #fed;
    color: #332;
}
.info-image{
    display: inline-block;
    width: 40%;
    text-align: center;
}
.info-name{
    display: inline-block;
    float: right;
    margin-top: 15px;
    width: 60%;
    text-align: left;
}
.info p{
    margin: 5px;
}
<div class="lookup" data-bind="dxLookup: {
    dataSource: lookupDataSource,
    displayExpr: 'name',
    valueExpr: 'this',
    pagingEnabled: false,
    title: 'States',
    onValueChanged: updateStateInfo
}"></div>
<div class="info dx-state-invisible">
    <div class="info-image">
        <img style="margin:5px;" data-bind="attr: { src: imagePath }"/>
    </div>
    <div class="info-name">
        <b style="text-align:center; font-size:larger;" data-bind="text: name"></b>
    </div>
    <p>Capital: <i data-bind="text: capital"></i></p>
    <p>Population: <i data-bind="text: population"></i></p>
    <p>Area: <i data-bind="text: area"></i></p>
</div>
var myViewModel = {
    name: ko.observable("none"),
    capital: ko.observable("none"),
    area: ko.observable("none"),
    population: ko.observable("none"),
    imagePath: ko.observable(""),
    lookupDataSource: new DevExpress.data.DataSource({
        store: [],
        paginate: false,
        map: function (dataItem) {
            dataItem.imagePath = "/Content/images/doc/15_1/PhoneJS/flags/" + dataItem.name.replace(" ", "") + ".gif";
            return dataItem;
        }
    }),
    updateStateInfo: function (e) {
        debugger
        $(".info.dx-state-invisible").removeClass("dx-state-invisible");
        this.name(e.value.name);
        this.capital(e.value.capital);
        this.area(e.value.area);
        this.population(e.value.population);
        this.imagePath(e.value.imagePath);
    }
}
$.get("/Content/data/states.txt", function (data) {
    for (var i = 0; i < data.length; i++) {
        myViewModel.lookupDataSource.store().insert(data[i]);
    }
    myViewModel.lookupDataSource.load();
}, "json");
ko.applyBindings(myViewModel);
.lookup{
    margin: 10px;
}
.info {
    margin: 10px;
    padding: 10px;
    border: solid 1px blue;
    background: #fed;
    color: #332;
}
.info-image{
    display: inline-block;
    width: 40%;
    text-align: center;
}
.info-name{
    display: inline-block;
    float: right;
    margin-top: 15px;
    width: 60%;
    text-align: left;
}
.info p{
    margin: 5px;
}
<div class="lookup" id="myLookup"></div>
<div class="info dx-state-invisible">
    <div class="info-image">
        <img style="margin:5px;" id="image"/>
    </div>
    <div class="info-name">
        <b style="text-align:center; font-size:larger;" id="stateField"></b>
    </div>
    <p>Capital: <i id="capitalField"></i></p>
    <p>Population: <i id="populationField"></i></p>
    <p>Area: <i id="areaField"></i></p>
</div>
var lookupDataSource = new DevExpress.data.DataSource({
    store: [],
    paginate: false,
    map: function (dataItem) {
        dataItem.imagePath = "/Content/images/doc/15_1/PhoneJS/flags/" + dataItem.name.replace(" ", "") + ".gif";
        return dataItem;
    }
});
$("#myLookup").dxLookup({
    dataSource: lookupDataSource,
    displayExpr: 'name',
    valueExpr: 'this',
    pagingEnabled: false,
    title: 'States',
    onValueChanged: function (e) {
        fillFields(e.value);
    }
});
var fillFields = function (data) {
    $(".info.dx-state-invisible").removeClass("dx-state-invisible");
    $("#stateField").text(data != null ? data.name : "none");
    $("#capitalField").text(data != null ? data.capital : "none");
    $("#populationField").text(data != null ? data.population : "none");
    $("#areaField").text(data != null ? data.area : "none");
    $("#image").attr("src", data != null ? data.imagePath : "")
}
$.get("/Content/data/states.txt", function (data) {
    for (var i = 0; i < data.length; i++) {
        lookupDataSource.store().insert(data[i]);
    }
    lookupDataSource.load();
}, "json");
.lookup{
    margin: 10px;
}
.info {
    margin: 10px;
    padding: 10px;
    border: solid 1px blue;
    background: #fed;
    color: #332;
}
.info-image{
    display: inline-block;
    width: 40%;
    text-align: center;
}
.info-name{
    display: inline-block;
    float: right;
    margin-top: 15px;
    width: 60%;
    text-align: left;
}
.info p{
    margin: 5px;
}

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 exposed by this widget.

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