[英]How to get selected row in angularjs UI-GRID on row selected event
I have an ui-grid in my application and I want to get the selected row when user select a row from the grid (single row selectable grid). 我的应用程序中有一个ui网格,当用户从网格(单行可选网格)中选择一行时,我想获取选定的行。
I know how to get the selected rows through gridApi when click on a button. 我知道如何在单击按钮时通过gridApi获取选定的行。 But I'm unable to get a selected row immediately at the row selected event.
但是我无法在行选定事件中立即获得选定行。
Need to register api function and use as shown below 需要注册api函数并按如下所示使用
$scope.gridOptions.onRegisterApi = function(gridApi){
$scope.gridApi = gridApi;
gridApi.selection.on.rowSelectionChanged($scope, function(row){
$scope.countRows = $scope.gridApi.selection.getSelectedRows().length;
});
gridApi.selection.on.rowSelectionChangedBatch($scope, function(row){
$scope.countRows = $scope.gridApi.selection.getSelectedRows().length;
});
};
You could bind ng-click on the row, that gets the $event. 您可以在行上绑定ng-click,获得$ event。
Modify the template and reference the appScope 修改模板并引用appScope
$templateCache.put('ui-grid/uiGridViewport',
....
"<div ng-repeat=\"(rowRenderIndex, row) in rowContainer.renderedRows track by $index\"" +
"ng-click=\"grid.appScope.onClickRow(row, $event)\"" +
....
);
JUST ADD : 只需添加:
gridApi.selection.on.rowSelectionChanged($scope,function(row){
console.log(row.entity);
});
in registor api function of ui grid. 在ui网格的注册器api函数中。 row.entity will give the selected row
row.entity将给出选定的行
more details here : http://ui-grid.info/docs/#/tutorial/210_selection 此处有更多详细信息: http : //ui-grid.info/docs/#/tutorial/210_selection
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.