I have an issue with restoring the selection in a Kendo dropdownlist after my application loads data from the database. When I set a breakpoint after restoring the selection, I can see that the dropdownlist has been set properly to the value to restore. However, when I continue after the breakpoint, the dropdownlist resets to its default value. What is causing the dropdown to reset?
We are using Kendo UI v2016.1.322, Internet Explorer 11.0.9600.18314, and Windows Server 2008 R2 Enterprise.
This is the markup for the dropdownlist :
<div class="panel panel-default" id="carEntriesPanel"
ng-repeat="carEntry in carEntries[selectedRouteIndex]">
<select class="form-control" kendo-drop-down-list k-options="kdCarTextOptions"
id="{{'carTextDropdown-' + $index}}" ng-model="carEntry.carTextSelected.id"
</select>
</div>
These are the options and data source:
$scope.kdCarTextOptions = {
optionLabel: 'Please Select',
dataSource: $scope.carTextDropDownDataSource,
dataTextField: 'name',
dataValueField: 'id',
select: $scope.onSelect
};
$scope.carTextDropDownDataSource = new kendo.data.DataSource({
transport: {
read: function (options) {
options.success($scope.carTexts[$scope.selectedRouteIndex]);
}
}
This is the onSelect method:
$scope.onSelect = function (e) {
var dataItem = this.dataItem(e.item);
$scope.carEntries[$scope.selectedRouteIndex][$scope.carIndex].carTextSelected.id = dataItem.id;
$scope.carEntries[$scope.selectedRouteIndex][$scope.carIndex].carTextSelected.name = dataItem.name;
};
}
This is the method that restores the dropdown selection. By setting breakpoints, I could see that the dropdownlist does show the restored value, and onSelect is called after the select is triggered. But when I continue after the trigger, the dropdownlist resets to its default value.
function updateCarTextDropdown(carIndex, carEntry) {
var dropdown = angular.element('#carTextDropdown-' + carIndex).data('kendoDropDownList');
if (dropdown) {
dropdown.dataSource.read();
if (carEntry.car.CAR_TXT_ID !== undefined) {
dropdown.value(carEntry.car.CAR_TXT_ID.toString());
dropdown.trigger('select');
}
}