DropDownBox

The DropDownBox widget consists of a text field, which displays the current value, and a drop-down field, which can contain any UI element.

Export: default

DevExtreme widgets are integrated with many popular libraries and frameworks. See the Installation section (for JavaScript libraries) or the Prerequisites and Installation section (for ASP.NET MVC framework) to find details on setting up DevExtreme with a particular library or framework.

The following code shows how to create the DropDownBox widget using every supported library and framework. For more details on working with widgets in these libraries and frameworks, see the Widget Basics topic for jQuery, Angular, AngularJS, Knockout or ASP.NET MVC.

jQuery
JavaScript
HTML
$(function () {
    var fruits = ["Apples", "Oranges", "Lemons", "Pears", "Pineapples"];
    $("#dropDownBox").dxDropDownBox({
        value: fruits[0],
        dataSource: fruits,
        contentTemplate: function (e) {
            var $list = $("<div>").dxList({
                dataSource: fruits,
                selectionMode: "single",
                onSelectionChanged: function (args) {
                    e.component.option("value", args.addedItems[0]);
                    e.component.close();
                }
            });
            return $list;
        }
    });
});
<div id="dropDownBox"></div>
Angular
HTML
TypeScript
<dx-drop-down-box
    [(value)]="selectedFruit"
    [(opened)]="isDropDownBoxOpened"
    [dataSource]="fruits">
    <div *dxTemplate="let contentData of 'content'">
        <dx-list 
            [dataSource]="fruits"
            selectionMode="single"
            (onSelectionChanged)="changeDropDownBoxValue($event)">
        </dx-list>
    </div>
</dx-drop-down-box>
import { DxDropDownBoxModule } from 'devextreme-angular';
// ...
export class AppComponent {
    fruits = ["Apples", "Oranges", "Lemons", "Pears", "Pineapples"];
    selectedFruit = fruits[0];
    isDropDownBoxOpened = false;
    changeDropDownBoxValue = function (args) {
        selectedFruit = args.addedItems[0];
        isDropDownBoxOpened = false;
    }
}
@NgModule({
    imports: [
        // ...
        DxDropDownBoxModule
    ],
    // ...
})
AngularJS
HTML
JavaScript
<div ng-controller="DemoController">
    <div dx-drop-down-box="{
        dataSource: fruits,
        bindingOptions: {
            value: 'selectedFruit',
            opened: 'isDropDownBoxOpened'
        }
    }">
        <div data-options="dxTemplate: { name: 'content' }">
            <div dx-list="{
                dataSource: fruits,
                selectionMode: 'single',
                onSelectionChanged: changeDropDownBoxValue
            }"></div>
        </div>
    </div>
</div>
angular.module('DemoApp', ['dx'])
    .controller('DemoController', function ($scope) {
        $scope.fruits = ["Apples", "Oranges", "Lemons", "Pears", "Pineapples"];
        $scope.selectedFruit = $scope.fruits[0];
        $scope.isDropDownBoxOpened = false;
        $scope.changeDropDownBoxValue = function (args) {
            $scope.selectedFruit = args.addedItems[0];
            $scope.isDropDownBoxOpened = false;
        }
    });
Knockout
HTML
JavaScript
<div data-bind="dxDropDownBox: {
    value: fruits[0],
    dataSource: fruits,
    opened: isDropDownBoxOpened
}">
    <div data-options="dxTemplate: { name: 'content' }">
        <div data-bind="dxList: {
            dataSource: fruits,
            selectionMode: 'single',
            onSelectionChanged: changeDropDownBoxValue
        }"></div>
    </div>
</div>
var viewModel = function () {
    var vm = { };
    vm.fruits = ["Apples", "Oranges", "Lemons", "Pears", "Pineapples"];
    vm.selectedFruit = ko.observable(vm.fruits[0]);
    vm.isDropDownBoxOpened = ko.observable(false);
    vm.changeDropDownBoxValue = function (args) {
        vm.selectedFruit(args.addedItems[0]);
        vm.isDropDownBoxOpened(false);
    }
    return vm;
};
ko.applyBindings(viewModel);
ASP.NET MVC Controls
Razor C#
Razor VB
@(Html.DevExtreme().DropDownBox()
    .ID("dropDownBox")
    .DataSource(new[] { "Apples", "Oranges", "Lemons", "Pears", "Pineapples" })
    .Value("Apples")
    .ContentTemplate(@<text>
        @(Html.DevExtreme().List()
            .DataSource(new JS("component.option('dataSource')"))
            .SelectionMode(ListSelectionMode.Single)
            .OnSelectionChanged("innerList_selectionChanged")
        )
    </text>)
)

<script>
    function innerList_selectionChanged (e) {
        var dropDownBox = $("#dropDownBox").dxDropDownBox("instance");
        dropDownBox.option("value", e.addedItems[0]);
        dropDownBox.close();
    }
</script>
@Code
    Html.DevExtreme().DropDownBox() _
        .ID("dropDownBox") _
        .DataSource({ "Apples", "Oranges", "Lemons", "Pears", "Pineapples" }) _
        .Value("Apples") _
        .ContentTemplate(Sub()
            @<text>
                @Html.DevExtreme().List() _
                    .DataSource(New JS("component.option('dataSource')")) _
                    .SelectionMode(ListSelectionMode.Single) _
                    .OnSelectionChanged("innerList_selectionChanged")
            </text>
        End Sub).Render()
End Code

<script>
    function innerList_selectionChanged (e) {
        var dropDownBox = $("#dropDownBox").dxDropDownBox("instance");
        dropDownBox.option("value", e.addedItems[0]);
        dropDownBox.close();
    }
</script>

View Demo Watch Video

Configuration

An object defining configuration options for the DropDownBox widget.

Methods

This section describes members used to manipulate data.

Events

This section describes events that this widget raises.

See Also