Search code examples
angularjsdevextreme

How to set value for DevExtreme DxCombobox?


How to set the Combobox'value (SelectedBox) from javascript code?

Demo of the component

http://js.devexpress.com/Demos/WidgetsGallery/#demo/editors-select_box-search_and_editing/angular/generic/light.compact

I need to set the value from javascript code, I use AngularJS!

from component's api I didn't see how to set it!

http://js.devexpress.com/Documentation/ApiReference/UI_Widgets/dxSelectBox/?version=15_2


Solution

  • There is the value option in the dxSelectBox API. Well, just set this option. If you want to use a two-way binding for the selectbox value, use the bindingOptions object.

    HTML

    <div dx-select-box="{dataSource: data, bindingOptions: { value: 'selectedItem' } }"></div>
    

    JS

    myApp.controller("myCtrl", function($scope) {
        $scope.data = [/* your data */];
        $scope.selectedItem = $scope.data[0];
    });
    

    I've created the small sample here.