2017-02-24 71 views
0

您好在angularjs項目中使用UIgrid,當我調用方法gridApi.selection.getSelectedRows()獲取選定的行時,它將以隨機順序返回包含所有行的數組。理想情況下,我想按照它們被選擇的順序來獲取行(就像gridApi.selection.getSelectedRows()由一個隊列支持)。任何想法如何實現這個請好嗎?ui grid按照選擇的順序返回行嗎?

此鏈接到plunker顯示http://plnkr.co/edit/gD4hiEO2vFGXiTlyQCix?p=preview

+0

後有問題, –

+0

小提琴我認爲這是該版本的角度我是用在那裏,如果你在plnkr的版本升級到最新的它的行爲的錯誤預期 – Mero

回答

1

你可以自己實現隊列。喜歡的東西

$scope.gridOnRegisterApi = function(gridApi) { 
    gridApi.selection.on.rowSelectionChanged($scope, function(row) { 
     var selections =gridApi.selection.getSelectedRows(); 
     // add sorted 
     selections.forEach(function(s){ 
     if ($scope.mySelections.indexOf(s) === -1) { 
      $scope.mySelections.push(s); 
     } 
     }); 
     // remove the ones that are not selected (use for to modify collection while iterating) 
     for (var i = $scope.mySelections.length; i >0; i--) { 
     if (selections.indexOf($scope.mySelections[i]) === -1) { 
      $scope.mySelections.splice(i, 1); 
     } 
     } 
     console.log($scope.mySelections); 
     row.entity.firstSelection = false; 
     if (row.isSelected) row.entity.firstSelection = (gridApi.selection.getSelectedCount() == 1); 
    }); 
    }; 
+1

我想到的但我想了解gridApi.selection.getSelectedRows()的行爲爲什麼它是如此隨機。那是我的計劃B :) – Mero

0

我認爲這是該版本的角度我是用在那裏,如果你在plnkr升級版本1.6.1它會像預期的那樣

錯誤的問題
相關問題