相关疑难解决方法(0)

从ng-grid获取选择的行?

如何在ng-grid中创建(或访问)所选行的数组?


文档(滚动到"网格选项")

id                 | default value | definition
-----------------------------------------------
selectedItems      |       []      | all of the items selected in the grid.
                                     In single select mode there will only
                                     be one item in the array.
Run Code Online (Sandbox Code Playgroud)

的index.html

<body ng-controller="MyCtrl">
    <div class="gridStyle" ng-grid="gridOptions"></div>

    <h3>Rows selected</h3>
    <pre>{{selectedItems}}</pre>
</body>
Run Code Online (Sandbox Code Playgroud)

main.js

var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope) {
    $scope.myData = [{name: "Moroni", age: 50},
                     {name: "Tiancum", age: 43},
                     {name: "Jacob", age: 27},
                     {name: "Nephi", age: 29},
                     {name: "Enos", age: 34}];
    $scope.gridOptions = …
Run Code Online (Sandbox Code Playgroud)

data-binding angularjs angularjs-directive angularjs-scope ng-grid

12
推荐指数
2
解决办法
4万
查看次数

获取angularjs ui-grid的选定行

我已经查看了关于这个 ui-grid 的多篇文章,它让我很适合。我正在尝试获取选定的行对象。我要么得到一个未定义的,要么无法读取“getSelectedRows”的属性。任何帮助是极大的赞赏。

我从这篇文章here开始,文档似乎也不是那么好。

这是我的代码:

        vm.gridOptions = {
        enableRowSelection: false,
        enableSelectAll: false,
        showGridFooter:true

    };

    vm.gridOptions.columnDefs = [
        { name: 'productName' },
        { name: 'unitPrice' }
    ];

    vm.gridOptions.multiSelect = false;

    vm.getSelectedRows = function () {
        vm.mySelectedRows = vm.gridApi.selection.getSelectedRows();
    }

     productDataService.getProductList()
         .then(function (result) {                 
             vm.gridOptions.data = result.data;
             vm.mySelectedRows = vm.gridApi.selection.getSelectedRows();<--Property undefined error here
             $timeout(function() {
                 if (vm.gridApi.selection.selectedRow) {
                     vm.gridApi.selection.selectRow(vm.gridOptions.data[0]);
                 }
             });
         });

    vm.gridOptions.onRegisterApi = function(gridApi) {
        vm.gridApi = gridApi;
    }
Run Code Online (Sandbox Code Playgroud)

angularjs angular-ui-grid ui-grid

3
推荐指数
1
解决办法
2万
查看次数