javascript - 每行的 Ui-Grid 单选按钮选择

标签 javascript angularjs angular-ui-grid

大家早上好! 我正在使用 Angular ui-Grid。最后一个字段应该包含 3 个单选按钮,用户可以在每行中选择这些按钮。所有的默认值都应该是 Value=0。问题是我只能在整个网格中选择 1 个单选按钮,而不是每行一个。我相信应该有办法做到这一点,但我一直无法弄清楚或在网上找到任何此类示例。这是我的网格的图片,它可能有助于更好地了解我要完成的工作:

enter image description here

最终,数据将来自对我们的 Web Api 的调用,但目前我正在用虚假数据填充网格。这是我的 Controller 代码:

 $scope.gridOptions = {};

    $scope.gridOptions = {
        columnDefs: [
      {
          name: 'CompanyID', width: '200'
      },
      {
          name: 'CompanyName', width: '200',
      },
      { name: 'City', width: '200' },
      { name: 'State', width: '150' },
      { name: 'Subscription', width: '150' },
      {
          name: 'ReleaseAction', width: '350',
          cellTemplate: '<div ng-init="releaseAction=0"><input name="Release" ng-model="releaseAction" type="radio" value="0" style="width:20px">&nbsp;None&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="Release" type="radio" ng-model="releaseAction"  value="1" style="width:20px">&nbsp;Accept&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="Release" type="radio" ng-model="releaseAction"  value="2" style="width:20px">&nbsp;Decline</div>'
      },

        ]
    };

    var gridData = [
        {
            CompanyID: 1,
            CompanyName: 'Tanner & Associates',
            City: 'Houston',
            State: 'TX',
            Subscription: 'Expired',
            //ReleaseAction: 0
        },
        {
            CompanyID: 2,
            CompanyName: 'Total Energy Services',
            City: 'Conroe',
            State: 'TX',
            Subscription: 'Active'
        },
        {
            CompanyID: 3,
            CompanyName: 'SPSD Inc',
            City: 'Arlington',
            State: 'TX',
            Subscription: 'Active'

        }
    ];

    $scope.gridOptions.data = gridData;

非常感谢任何帮助!

最佳答案

我能够通过从每个按钮中删除 name="Release"来获得所需的结果。新的单元格模板如下所示:

  cellTemplate: '<div class="btn-group" ng-init="releaseAction=0"><input ng-model="releaseAction" type="radio" value="0" style="width:20px">&nbsp;None&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input ng-model="releaseAction" type="radio" value="1" style="width:20px">&nbsp;Accept&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input ng-model="releaseAction" type="radio" value="2" style="width:20px">&nbsp;Decline</div>'

我希望这对其他人有帮助!

关于javascript - 每行的 Ui-Grid 单选按钮选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33393657/

相关文章:

javascript - 如何仅在特定网址中添加 JavaScript 代码?

javascript - morris 图表 -> html 将变量传递给 php

javascript - 使用 JavaScript 插入 Access 数据库

javascript - 显示 onFocus 和 hide 以及 onBlur 在 angular js 中组合的时间

javascript - 如何在一个地方重复?

javascript - 从日期时间格式化时间

javascript - 来自 json 文件的 Angular ui 网格

javascript - 如何根据来自 json 的数据更改选择按钮颜色?

javascript - history.js Github 喜欢 URL 更改 - 用斜杠更改 url 的部分

javascript - 循环 promise 响应的正确方法