UI Widgets SelectBox

A widget that allows you to select an item in a dropdown list.

Included in: dx.mobile.js, dx.web.js, dx.viz-web.js, dx.all.js
Module: ui/select_box
SelectBox interactive configuration
Copy code
$("#selectbox").dxSelectBox({
});

The SelectBox widget is a drop-down list of selectable items.

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

  • jQuery
    Use the dxSelectBox jQuery plug-in.

    HTML
    <div id="selectBox"></div>
    JavaScript
    var selectBoxData = [
        { "name": "Alabama", "capital": "Montgomery" },
        { "name": "Alaska", "capital": "Juneau" },
        { "name": "Arizona", "capital": "Phoenix" }
        . . .
    ]
    $("#selectBox").dxSelectBox({
        dataSource: selectBoxData,
        valueExpr: 'capital',
        displayExpr: 'name'
    });
  • Knockout
    Add a div element and apply the dxSelectBox binding to this element.

    HTML
    <div data-bind="dxSelectBox: {
        dataSource: selectBoxData,
        valueExpr: 'capital',
        displayExpr: 'name'
    }"></div>
  • AngularJS
    Add a div element and apply the dx-select-box directive to this element.

    HTML
    <div dx-select-box="{
        dataSource: selectBoxData,
        valueExpr: 'capital',
        displayExpr: 'name'
    }"></div>

Note that DevExtreme widgets require you to link the jQuery library to your application. If you use the Knockout or AngularJS approach, the Knockout or AngularJS library is also required. For detailed information on linking these libraries to your project, refer to the Installation article.

The SelectBox widget supports common Collection Container and Editor widget functionality. You can find detailed information on the principles of working with the widget in the dxSelectBox section of the Editor Widgets article. For the information on using the Collection Container functionality, refer to the Collection Container Widgets guide.

View Demo

Show Example:
AngularJS
Knockout
jQuery
<div ng-controller="demoController">
    <div ng-model="capital" dx-select-box="{
        dataSource: selectBoxData,
        placeholder: 'Select a state',
        displayExpr: 'name',
        valueExpr: 'capital'
    }"></div>
    <div>
        <p>Selected state capital: <b>{{capital}}</b></p>
    </div>
</div>
var myApp = angular.module('myApp', ['dx']);
myApp.controller("demoController", function ($scope) {
    $scope.capital = "";
    $scope.selectBoxData = new DevExpress.data.DataSource({ store: [], paginate: false });
    $.get("/Content/data/states.txt", function (data) {
        for (var i = 0; i < data.length; i++) {
            $scope.selectBoxData.store().insert(data[i]);
        }
        $scope.selectBoxData.load();
    }, "json");
});
angular.element(document).ready(function () {
    angular.bootstrap(document, ['myApp']);
});
body {
    text-align: center;
}
.dx-selectbox {
    margin: 10px;
}
<div data-bind="dxSelectBox:{
    dataSource: selectBoxData,
    placeholder: 'Select a state',
    displayExpr: 'name',
    valueExpr: 'capital',
    value: capital
}"></div>
<div>
    <p>Selected state capitals: <b data-bind="text: capital"></b></p>
</div>
var myViewModel = {
    capital: ko.observable(""),
    selectBoxData: new DevExpress.data.DataSource({ store: [], paginate: false })
}
$.get("/Content/data/states.txt", function (data) {
    for (var i = 0; i < data.length; i++) {
        myViewModel.selectBoxData.store().insert(data[i]);
    }
    myViewModel.selectBoxData.load();
}, "json");
ko.applyBindings(myViewModel);
body {
    text-align: center;
}
.dx-selectbox {
    margin: 10px;
}
<div id="mySelectBox"></div>
<div>
    <p>Selected state capital: <b id="capital"></b></p>
</div>
var selectBoxData = new DevExpress.data.DataSource({ store: [], paginate: false });
$("#mySelectBox").dxSelectBox({
    dataSource: selectBoxData,
    placeholder: 'Select a state',
    displayExpr: 'name',
    valueExpr: 'capital',
    onValueChanged: function (e) {
        $("#capital").text(e.value);
    }
});
$.get("/Content/data/states.txt", function (data) {
    for (var i = 0; i < data.length; i++) {
        selectBoxData.store().insert(data[i]);
    }
    selectBoxData.load();
}, "json")
body {
    text-align: center;
}
.dx-selectbox {
    margin: 10px;
}

Configuration

An object defining configuration options for the SelectBox widget.

Methods

This section describes members used to manipulate the widget.

Events

This section describes events fired by this widget.

Default Item Template

This section lists the data source fields that are used in a default item template.

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