Where can I get Angular ui-grid selected items

时间秒杀一切 提交于 2019-11-28 21:06:14

Is this what your are looking for ? http://ui-grid.info/docs/#/tutorial/210_selection

  1. Activate grid selection capabilities with the ui-grid-selection tag (and ui.grid.selection module registration in your app
  2. register gridApi and use gridApi.selection to access getSelectedRows()
Rajush

In addition to the steps above https://stackoverflow.com/a/26188783/2658127, you might have to invoke it through a ng-click event to get the actual value/object. At least that's how I had it working.

Eg:
$scope.selectRow = function(){
    $scope.gridApi.selection.getSelectedRows();
};

And call selectRow() from the template.

This is for anybody who have been confused like I did, considering the fact that ui-grid does not have the best documentation (specially for this select portion).

Arashsoft

The easiest approach is:

  1. Register the gridApi by adding this your controller:

    $scope.gridOptions.onRegisterApi = function(gridApi) { $scope.myGridApi = gridApi; };

  2. Access the array of selected items:

    $scope.myGridApi.selection.getSelectedRows();

Panciz

With grid ui you have to use the selection.on.rowSelectionChanged to update a scope variable that store the selectedItem. In this way you can use the value in a binding expression.

var SelectController = function($scope) {
    ...
    $scope.selectedItem = null;

    $scope.gridOptions = {
            data : 'articles',
            enableRowSelection : true,
            multiSelect : false,
            enableRowHeaderSelection : false,
            ...
        };

        $scope.gridOptions.onRegisterApi = function(gridApi) {
            // set gridApi on scope
            this.$scope.gridApi = gridApi;
        }.bind(this);
        $scope.gridOptions.onRegisterApi = function(gridApi) {
            // set gridApi on scope
            this.$scope.gridApi = gridApi;
            this.$scope.gridApi.selection.on.rowSelectionChanged($scope,
                    function(row) {
                        this.$scope.selectedItem = row.entity;
                    }.bind(this));
        }.bind(this);

Use a an array instead of a plain object if you need multiple selection.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!