早安全部! 我正在使用Angular ui-Grid。最后一个字段应该包括3个用户可以按行选择的单选按钮。 all的默认值应为Value = 0。问题是我只能在整个网格中选择1个单选按钮而不是每行一个。我相信应该有办法实现这一目标,但我一直无法弄清楚或找到任何这样的网上示例。这是我的网格图片,它可能有助于更好地了解我想要实现的目标:
最终,数据将来自对我们的Web Api的调用,但目前我正在使用虚假数据填充网格。这是我的控制器代码:
$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"> None <input name="Release" type="radio" ng-model="releaseAction" value="1" style="width:20px"> Accept <input name="Release" type="radio" ng-model="releaseAction" value="2" style="width:20px"> 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;
非常感谢任何帮助!
答案 0 :(得分:1)
通过删除name =&#34; Release&#34;我能够获得所需的结果。从每个按钮。新的单元格模板如下所示:
cellTemplate: '<div class="btn-group" ng-init="releaseAction=0"><input ng-model="releaseAction" type="radio" value="0" style="width:20px"> None <input ng-model="releaseAction" type="radio" value="1" style="width:20px"> Accept <input ng-model="releaseAction" type="radio" value="2" style="width:20px"> Decline</div>'
我希望这有助于其他人!
答案 1 :(得分:1)
这是因为所有单选按钮的名称相同。因此,一个解决方法是将每行的索引附加到名称。
这是plucker链接 http://plnkr.co/edit/VXpWT8MYwp9bNfF11vHM?p=preview
cellTemplate:
<div ng-init="releaseAction=0"><input name="Release{{grid.renderContainers.body.visibleRowCache.indexOf(row)}}" ng-model="releaseAction" type="radio" ng-value="0" style="width:20px"> None <input name="Release{{grid.renderContainers.body.visibleRowCache.indexOf(row)}}" type="radio" ng-model="releaseAction" ng-value="1" style="width:20px"> Accept <input name="Release{{grid.renderContainers.body.visibleRowCache.indexOf(row)}}" type="radio" ng-model="releaseAction" ng-value="2" style="width:20px"> Decline</div>