角度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中没有发现此类事件的迹象文档。
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 :(.