javascript - Angular ui-grid 3.0获取选定的行

标签 javascript angularjs angular-ui-grid

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/

相关文章:

javascript - 如何在 javascript 中对这个对象数组进行排序?

javascript - $ ('title' ).text() 在 IE 中不起作用

html - 如何强制使用 CSS 显示 : table to fit within a minimum height? 制作的表格

angularjs - Angular 2 成熟度 : going in prod with usable components

javascript - 将几个切换功能合并为一个,切换不再起作用

javascript - 电子邮件表格未发送

javascript - angularjs 在 safari 和 IE 11 中正式提交错误

angularjs - 如何在 ionic 项目中设置起始页

javascript - Angular UI Grid 在导航时将焦点设置为单元格

angular-ui-grid - ui 网格过滤器切换不起作用, "type was not recognised"?