我在哪里可以得到角ui网格选择项目

时间:2022-08-24 11:46:50

Testing out Angular ui-grid (ng-grid v.3.0). Can not for the life of me find the selected row. I just want to grab the rows or even row ID of row when a user clicks it. Found the top comment here but I think this is outdated: Getting select rows from ng-grid?

测试角度ui网格(ng-grid v.3.0)。无法为我的生命找到所选择的行。我只是想在用户单击它时获取行或甚至行ID。在这里找到了上面的注释,但是我认为这已经过时了:从ng-grid中获取选择行?

Does anyone know where the gridOptions.selectedItems is being stored in 3.0?

有人知道gridOptions在哪里吗?selectedItems存储在3.0中吗?

4 个解决方案

#1


34  

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

这是你要找的吗?/ 210 _selection http://ui-grid.info/docs/ /教程

  1. Activate grid selection capabilities with the ui-grid-selection tag (and ui.grid.selection module registration in your app
  2. 使用ui网格选择标记(和ui.grid)激活网格选择功能。选择模块注册在你的应用
  3. register gridApi and use gridApi.selection to access getSelectedRows()
  4. 注册gridApi并使用gridApi。选择访问getSelectedRows()

#2


23  

In addition to the steps above https://*.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.

除了上面的步骤之外,您可能还需要通过ng-click事件调用它来获取实际的值/对象。至少我是这么做的。

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

And call selectRow() from the template.

并从模板调用selectRow()。

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).

考虑到ui-grid没有最好的文档(特别是对于这个select部分),这对于像我这样困惑的任何人来说都是如此。

#3


15  

The easiest approach is:

最简单的方法是:

  1. Register the gridApi by adding this your controller:

    通过添加此控制器注册gridApi:

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

    scope.gridOptions美元。onRegisterApi =函数(gridApi){$范围。myGridApi = gridApi;};

  2. Access the array of selected items:

    访问所选项目的数组:

    $scope.myGridApi.selection.getSelectedRows();

    美元scope.myGridApi.selection.getSelectedRows();

#4


0  

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.

使用grid ui,您必须使用selection.on。rowSelectionChanged来更新存储selectedItem的范围变量。通过这种方式,您可以在绑定表达式中使用该值。

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.

如果需要多个选择,请使用数组而不是普通对象。

#1


34  

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

这是你要找的吗?/ 210 _selection http://ui-grid.info/docs/ /教程

  1. Activate grid selection capabilities with the ui-grid-selection tag (and ui.grid.selection module registration in your app
  2. 使用ui网格选择标记(和ui.grid)激活网格选择功能。选择模块注册在你的应用
  3. register gridApi and use gridApi.selection to access getSelectedRows()
  4. 注册gridApi并使用gridApi。选择访问getSelectedRows()

#2


23  

In addition to the steps above https://*.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.

除了上面的步骤之外,您可能还需要通过ng-click事件调用它来获取实际的值/对象。至少我是这么做的。

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

And call selectRow() from the template.

并从模板调用selectRow()。

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).

考虑到ui-grid没有最好的文档(特别是对于这个select部分),这对于像我这样困惑的任何人来说都是如此。

#3


15  

The easiest approach is:

最简单的方法是:

  1. Register the gridApi by adding this your controller:

    通过添加此控制器注册gridApi:

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

    scope.gridOptions美元。onRegisterApi =函数(gridApi){$范围。myGridApi = gridApi;};

  2. Access the array of selected items:

    访问所选项目的数组:

    $scope.myGridApi.selection.getSelectedRows();

    美元scope.myGridApi.selection.getSelectedRows();

#4


0  

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.

使用grid ui,您必须使用selection.on。rowSelectionChanged来更新存储selectedItem的范围变量。通过这种方式,您可以在绑定表达式中使用该值。

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.

如果需要多个选择,请使用数组而不是普通对象。