角度ui-grid事件:选择行 [英] angular ui-grid event: row selected

查看:168
本文介绍了角度ui-grid事件:选择行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据在ui-grid上选择行来启用/禁用按钮。如果没有选择行,则按钮被禁用。

I am trying to enable/disable a button based on the selection of a row on a ui-grid. If there are no rows selected, the button is disabled.

我发现这是 plunkr 使用旧的ng-grid方式在选择一行后触发事件。

I found this plunkr with the old ng-grid way of firing an event after a row is selected.

  $scope.gridOptions = { 

  data: 'myData', 
  selectedItems: $scope.selections,
  enableRowSelection: true,

  afterSelectionChange:function() {
        if ($scope.selections != "" ) {
            $scope.disabled = false;
        } else {
            $scope.disabled = true;
        }
  }
};

不幸的是它不起作用,我在ui-grid中没有发现此类事件的迹象< a href =http://ui-grid.info/docs/#/api>文档。

Unfortunately it does not work, and I have found no sign of such event in the ui-grid documentation.

如何通过ui-实现这一目标grid?

How can I achieve that with ui-grid?

推荐答案

在ui-grid中,您在事件rowSelectionChanged上注册一个回调函数

In ui-grid, you register a callback function on the event "rowSelectionChanged"

 $scope.gridOptions.onRegisterApi = function (gridApi) {
                $scope.gridApi = gridApi;
                gridApi.selection.on.rowSelectionChanged($scope, callbackFunction);
                gridApi.selection.on.rowSelectionChangedBatch($scope, callbackFunction);
            }
 }

 function callbackFunction(row) { 
    var msg = 'row selected ' + row.isSelected; $log.log(msg); 
 })

我想你应该看一下ui-grid的教程页面: http://ui-grid.info/docs/#/tutorial/210_selection。在我看来,API页面很糟糕:(。

I think you should take a look at the tutorial page in ui-grid: http://ui-grid.info/docs/#/tutorial/210_selection. The API page sucks, in my opinion :(.

这篇关于角度ui-grid事件:选择行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆