javascript Angular ui-grid 3.0 获取选定的行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30366860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Angular ui-grid 3.0 get selected rows
提问by kitensei
This answerstates that this code:
此答案指出此代码:
$scope.gridOptions.onRegisterApi = function(gridApi){
$scope.gridApi = gridApi;
$scope.mySelectedRows=$scope.gridApi.selection.getSelectedRows();
}
Should work in order to get the selected rows, but to me it returns always [], to get track of selected rows I have to call gridApi.selection.getSelectedRows()
each time a selection event is triggered, is this correct ?
应该工作以获得选定的行,但对我来说它总是返回 [],以跟踪gridApi.selection.getSelectedRows()
每次触发选择事件时我必须调用的选定行,这是正确的吗?
What I want to achieve is to do my own footer that tracks the number of selected rows of the grid, is this the correct way of achieving this ?
我想要实现的是做我自己的页脚来跟踪网格的选定行数,这是实现这一目标的正确方法吗?
回答by Kathir
There is already an example of showing the number of selected elements in the footer.
已经有一个在页脚中显示所选元素数量的示例。
This plnkr shows the selected items footer. http://plnkr.co/edit/jc1YPCXBmfOKWyu8sLkx?p=preview
此 plnkr 显示所选项目的页脚。http://plnkr.co/edit/jc1YPCXBmfOKWyu8sLkx?p=preview
If you want to do further analysis on the selected row you can register a listener for the row selection and act on that.
如果您想对所选行进行进一步分析,您可以为行选择注册一个侦听器并对其进行操作。
$scope.gridOptions.onRegisterApi = function(gridApi){
//set gridApi on scope
$scope.gridApi = gridApi;
gridApi.selection.on.rowSelectionChanged($scope,function(row){
var msg = 'row selected ' + row.isSelected;
$log.log(msg);
});
gridApi.selection.on.rowSelectionChangedBatch($scope,function(rows){
var msg = 'rows changed ' + rows.length;
$log.log(msg);
});
};
回答by Roman K
I have it working w/o having to use the event trigger. I added a function, tied it to a button and can retrieve selected items only when I need them.
我让它工作而不必使用事件触发器。我添加了一个功能,将它绑定到一个按钮,并且可以仅在需要时检索所选项目。
$scope.gridOptions = {
data: 'data',
enableRowSelection: true,
onRegisterApi: function(gridApi) { //register grid data first within the gridOptions
$scope.gridApi = gridApi;
}
};
//this is the on click function
$scope.getCurrentSelection = function() {
var currentSelection = $scope.gridApi.selection.getSelectedRows();
console.log(currentSelection);
};
回答by KARTHIKEYAN.A
This function is work for me when selectAll function activated i have get the all selected rows.
当 selectAll 功能激活时,此功能对我有用,我已获得所有选定的行。
gridApi.selection.on.rowSelectionChangedBatch($scope,function(rows){
console.log(row);
});
回答by elciospy
$scope.gridOptions = {
data: 'data',
enableRowSelection: true,
onRegisterApi: function(gridApi) { //register grid data first within the gridOptions
$scope.gridApi = gridApi;
}
};
After you have access to the variable {{vm.gridApi.selection.getSelectedRows().length}} in template html directily.
在您可以直接访问模板 html 中的变量 {{vm.gridApi.selection.getSelectedRows().length}} 后。