2017-02-27 5 views
1

午前のプロジェクトでUI-GRIDを使用する選択された行の順序を追跡する方法がありますか(ユーザーが行を選択/選択解除できるようにする) gridApi.selection.getSelectedRows()戻り値は.Anyアイデアしてください? http://plnkr.co/edit/gD4hiEO2vFGXiTlyQCix?p=preview。 (要素をどのように保存するかをランダムに選択/選択解除するとplnkrがその問題を強調するのに役立つかもしれません)UIグリッドで選択した行の順序を追跡する方法は?

答えて

1

私はこれがあなたが望むものに近いかもしれないと信じています。

enter image description here

のJavaScript/AngularJSコントローラー:

var app = angular.module('app', ['ui.grid', 'ui.grid.selection']); 
app.controller('MainCtrl', ['$scope', '$http', function($scope, $http) { 
    $scope.mySelections = []; 
    $scope.mySelectionsInOrder = []; 
    $scope.gridOnRegisterApi = function(gridApi) { 
    gridApi.selection.on.rowSelectionChanged($scope, function(row) { 
     $scope.mySelections = gridApi.selection.getSelectedRows(); 
     if (row.isSelected) { 
     $scope.mySelectionsInOrder.push(row.entity); 
     } else { 
     $scope.mySelectionsInOrder.splice($scope.mySelectionsInOrder.indexOf(row.entity), 1); 
     } 
     console.log($scope.mySelections); 
    }); 
    }; 
    $scope.gridOptions = { 
    enableSelectAll: true, 
    enableRowSelection: true, 
    enableRowHeaderSelection: false, 
    enableFullRowSelection: true, 
    showGridFooter: true, 
    onRegisterApi: $scope.gridOnRegisterApi 
    } 
    $http.get('data.json') 
    .then(function(response) { 
     $scope.gridOptions.data = response.data; 
    }); 
}]); 

基本的な考え方は、私たちがpushspliceか否かのrowSelectionChangedイベント中の選択を追跡し、row.isSelectedを決定することです。

ここには、作業中のPlunker、http://plnkr.co/edit/lnng9coOQHca3PzOSjQI?p=previewがあります。

ご希望の方は、これ以上お問い合わせください。

関連する問題