问题
I am using UI-Grid to show data of attendance in my angular app.I have used i have three options for attendance stored in separate array.
$scope.gridOptions.data.attendance=[{'persent'},{'absent'},{'leave'}];
and number of students are shown as:
$scope.gridOptions.data=students;//from ajax request
Now i want to show dropdown in attendance column as.
I also want to show the persent as default selected option.so i used ng-options in celltemplate and code is like:
$scope.gridOptions = {
columnDefs: [
{
name: "stdattendance",
displayName: "Attendance",
width: '20%',
cellClass: 'grid-align',
cellTemplate:'<select ng-model="row.entity.stdattendnce" ng-init="row.entity.stdattendnce=row.entity.attendance[0]"
ng-options="s as s.description for s in row.entity.attendance track by s.id"></select>'
}]
The problems i am facing are:
1-the default options persent is selected in the grid shown without scrolling while in lower part of grid it is not selected.
2-When i am selecting an option it is also selected in some of lower grid randomly.
I can't figure out this strange behavior.will anyone help here???
回答1:
ng-init="row.entity.stdattendnce=row.entity.attendance[0] Is the typo causing a problem? It would help to see this in a plunkr. This is the angular plunkr: https://plnkr.co/edit/RJZXudKJKBVIKhoxjXW0
<body ng-app="defaultValueSelect">
<div ng-controller="ExampleController">
<form name="myForm">
<label for="mySelect">Make a choice:</label>
<select name="mySelect" id="mySelect"
ng-options="option.name for option in data.availableOptions track by option.id"
ng-model="data.selectedOption"></select>
</form>
<hr>
<tt>option = {{data.selectedOption}}</tt><br/>
</div>
</body>
Notice that the selected option is set in the scope and identified in the template using ng-model.
来源:https://stackoverflow.com/questions/42206395/celltemplate-in-angular-ui-grid-is-not-working-properly