angular ui-grid 事件:行被选中 [英] angular ui-grid event: row selected
问题描述
我正在尝试根据 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 文档中没有发现此类事件的迹象.
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 :(.
这篇关于angular ui-grid 事件:行被选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!