您正在angularjs
项目中使用UIgrid,当我调用方法gridApi.selection.getSelectedRows()
来获取所选行时,它会返回一个包含所有行但是以随机顺序排列的数组。理想情况下,我希望按照选择的顺序获取行(就像gridApi.selection.getSelectedRows()
由队列支持一样)。知道如何实现这个目标吗?
此plunker链接显示问题http://plnkr.co/edit/gD4hiEO2vFGXiTlyQCix?p=preview
答案 0 :(得分: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 :(得分:0)
我认为我在那里使用的角度版本存在一个错误,如果将plnkr中的版本升级到1.6.1,它将按预期运行