Help us shape the 2021 DevExtreme Roadmap. Take our 5 minute survey.
Your search did not match any results.
Drop Down Box

Single Selection

The DropDownBox widget is an editor that consists of a text field and drop-down content. In this demo, the content is the TreeView and the DataGrid widgets in the single selection mode.

The following instructions show how to synchronize the DropDownBox widget with any other embedded DevExtreme widget:

  1. Specify data sources
    The DropDownBox's and embedded widget's data sources can be the same or different. If they are different, the widget's key field should be present in the DropDownBox's data source.

  2. Specify which data field provides the DropDownBox's values and the embedded widget's keys
    Assign the field's name to the DropDownBox's valueExpr option and to the key option of the embedded widget's store.

  3. Synchronize the DropDownBox's value and the embedded widget's selection

    1. Select data items according to the DropDownBox's initial value. To do this, assign the value to the embedded widget's selectedRowKeys/selectedItemKeys option (see the example with the DataGrid below). If the widget does not have such options, implement the onContentReady handler (the example with the TreeView).
    2. Implement the DropDownBox's onValueChanged handler to update the selection when the value changes.
    3. Implement the embedded widget's onSelectionChanged handler to update the DropDownBox's value when the selection changes.
Copy to CodePen
var DemoApp = angular.module('DemoApp', ['dx']); DemoApp.controller('DemoController', function DemoController($scope) { var treeView; var syncTreeViewSelection = function(treeView){ if (!treeView) return; if (!$scope.treeBoxValue) { treeView.unselectAll(); } else { treeView.selectItem($scope.treeBoxValue); } }; var makeAsyncDataSource = function(jsonFile){ return new{ loadMode: "raw", key: "ID", load: function() { return $.getJSON("../../../../data/" + jsonFile); } }); }; var treeDataSource = makeAsyncDataSource("treeProducts.json"), gridDataSource = makeAsyncDataSource("customers.json"); $scope.treeBoxValue = "1_1"; $scope.treeBoxOptions = { bindingOptions: { value: 'treeBoxValue' }, valueExpr: "ID", displayExpr: "name", placeholder: "Select a value...", showClearButton: true, dataSource: treeDataSource, onValueChanged: function(){ syncTreeViewSelection(treeView); }, treeView: { dataSource: treeDataSource, dataStructure: "plain", keyExpr: "ID", parentIdExpr: "categoryId", displayExpr: "name", selectByClick: true, selectNodesRecursive: false, selectionMode: "single", onContentReady: function(e) { treeView = e.component; syncTreeViewSelection(treeView); }, onItemSelectionChanged: function(args){ $scope.treeBoxValue = args.component.getSelectedNodeKeys(); } } }; $scope.gridBoxValue = 3; $scope.gridSelectedRowKeys = [$scope.gridBoxValue]; $scope.gridBoxOptions = { bindingOptions: { value: "gridBoxValue" }, valueExpr: "ID", deferRendering: false, placeholder: "Select a value...", displayExpr: function(item){ return item && item.CompanyName + " <" + item.Phone + ">"; }, onValueChanged: function(e){ $scope.gridSelectedRowKeys = e.value || []; }, showClearButton: true, dataSource: gridDataSource, dataGrid: { dataSource: gridDataSource, columns: ["CompanyName", "City", "Phone"], hoverStateEnabled: true, paging: { enabled: true, pageSize: 10 }, filterRow: { visible: true }, scrolling: { mode: "infinite" }, selection: { mode: "single" }, height: "100%", bindingOptions: { "selectedRowKeys": "gridSelectedRowKeys" }, onSelectionChanged: function(selectedItems){ var keys = selectedItems.selectedRowKeys; $scope.gridBoxValue = keys.length && keys[0] || null; } } }; });
<!DOCTYPE html> <html xmlns=""> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge"/> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/> <script src=""></script> <script>window.jQuery || document.write(decodeURIComponent('%3Cscript src="js/jquery.min.js"%3E%3C/script%3E'))</script> <link rel="stylesheet" type="text/css" href=""/> <link rel="stylesheet" type="text/css" href=""/> <script src=""></script> <script>window.angular || document.write(decodeURIComponent('%3Cscript src="js/angular.min.js"%3E%3C/script%3E'))</script> <script src=""></script> <link rel="stylesheet" type="text/css" href="styles.css"/> <script src="index.js"></script> </head> <body class="dx-viewport"> <div class="demo-container" ng-app="DemoApp" ng-controller="DemoController"> <div id="form"> <div class="dx-fieldset"> <div class="dx-field"> <div class="dx-field-label">DropDownBox with embedded TreeView</div> <div class="dx-field-value"> <div dx-drop-down-box="treeBoxOptions"> <div data-options="dxTemplate: { name: 'content' }"> <div dx-tree-view="treeBoxOptions.treeView"></div> </div> </div> </div> </div> <div class="dx-field"> <div class="dx-field-label">DropDownBox with embedded DataGrid</div> <div class="dx-field-value"> <div dx-drop-down-box="gridBoxOptions"> <div data-options="dxTemplate: { name: 'content' }"> <div dx-data-grid="gridBoxOptions.dataGrid"></div> </div> </div> </div> </div> </div> </div> </div> </body> </html>
#form .dx-fieldset { height: 500px; }