SelectBox

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

Type: Object

The dxSelectBox widget is a dropdown list of selectable items. To create the dxSelectBox widget, add a div element with dxSelectBox Knockout binding within the body of the required view.

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

The select box items are loaded from an array specified via the dataSource configuration option. You can specify a simple array or the 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 select box items, a default template is applied based on the following fields of the data source item objects.

  • disabled - specifies whether or not the select box item is disabled.
  • visible - specifies whether or not the select box 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 select box 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 dxSelectBox widget.

Methods

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

Events

This section describes events fired by this component.