angular-ui-grid 中的 Celltemplate 无法正常工作 [英] Celltemplate in angular-ui-grid is not working properly

查看:25
本文介绍了angular-ui-grid 中的 Celltemplate 无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用

我还想将 persent 显示为默认选择的选项.所以我在 celltemplate 中使用了 ng-options,代码如下:

 $scope.gridOptions = {列定义:[{名称: "stdattendance",displayName: "出勤",宽度: '20%',cellClass: '网格对齐',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>'}]

我面临的问题是:

1-在不滚动的情况下显示的网格中选择了默认选项,而在网格的下部未选择.

2-当我选择一个选项时,它也会在一些较低的网格中随机选择.

我无法弄清楚这种奇怪的行为.有人会在这里帮忙吗???

解决方案

ng-init="row.entity.stdattendnce=row.entity.attendance[0]错别字会导致问题吗?在 plunkr 中看到这一点会有所帮助.这是角度 plunkr:https://plnkr.co/edit/RJZXudKJKBVIKhoxjXW0

<div ng-controller="示例控制器"><表单名称="myForm"><label for="mySelect">做出选择:</label><选择名称="mySelect" id="mySelect"ng-options="option.name for option in data.availableOptions track by option.id"ng-model="data.selectedOption"></select></表单><小时><tt>option = {{data.selectedOption}}</tt><br/>

请注意,所选选项是在范围中设置的,并在模板中使用 ng-model 进行标识.

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???

解决方案

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.

这篇关于angular-ui-grid 中的 Celltemplate 无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆