This answer指出此代码:
$scope.gridOptions.onRegisterApi = function(gridApi){
$scope.gridApi = gridApi;
$scope.mySelectedRows=$scope.gridApi.selection.getSelectedRows();
}
为了获取选定的行应该工作,但对我来说它总是返回 [],以跟踪选定的行我必须调用 gridApi.selection.getSelectedRows()
每次选择事件被触发,这是正确的吗?
我想要实现的是做我自己的页脚来跟踪网格的选定行数,这是实现此目的的正确方法吗?
最佳答案
我无需使用事件触发器即可正常工作。我添加了一个功能,将其绑定(bind)到一个按钮,并且仅在我需要时才可以检索选定的项目。
$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);
};
关于javascript - Angular ui-grid 3.0获取选定的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30366860/