12

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.

index.html

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

    <h3>Rows selected</h3>
    <pre>{{selectedItems}}</pre>
</body>

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 = { data: 'myData' };
});

コード用の Plnkr (およびそれを実行するため)

4

5 に答える 5

23

ドキュメントに基づいて、selectedItemsのプロパティである必要がある$scope.gridOptionsため、これを試してください:

コントローラ

$scope.gridOptions = { data: 'myData', selectedItems: [] };

HTML

<pre>{{gridOptions.selectedItems}}</pre>
于 2013-06-01T17:38:16.997 に答える
7

以下から ng-grid 2.x の選択した項目を取得できます。

$scope.gridOptions.$gridScope.selectedItems
于 2014-08-06T16:31:08.333 に答える
4

バージョン 3 では、次のことができます。

$scope.gridOptions.onRegisterApi = function(gridApi){

  $scope.gridApi = gridApi;
  $scope.mySelectedRows=$scope.gridApi.selection.getSelectedRows();
}

詳細については、http://ui-grid.info/docs/#/api/ui.grid.selection.api: PublicApiを参照してください。

于 2014-11-27T09:01:44.947 に答える
3

3.0 の場合、次のように選択された行をキャプチャできます。

$scope.gridOptions.onRegisterApi = function(gridApi){
  //set gridApi on scope
  $scope.gridApi = gridApi;
  gridApi.selection.on.rowSelectionChanged($scope,function(row){
    var msg = 'row selected ' + row.isSelected;
    $log.log(msg);
  });
};

詳細はこちら: http://ui-grid.info/docs/#/tutorial/210_selection

于 2014-10-05T13:15:28.700 に答える
1

現在、選択した行のリストを読み込もうとしています。オプションは移動したようですが、次の場所にあります。

$scope.gridOptions.ngGrid.config.selectedItems

読み取り専用のようです

于 2014-07-18T23:14:40.107 に答える