ng grid shift select bug选择其他行

时间:2015-05-29 08:49:52

标签: javascript angularjs ng-grid

结帐我的plunker:link

var app = angular.module('app', []);
// some stupid error won't let me paste the whole code, please check plunker

重现:

  1. 通过鼠标左键单击
  2. 选择第一行
  3. 使用 ctrl + end 滚动到底行
  4. 选择显示'选择我...'使用 shift + 点击
  5. 预期:行直到“选择我......”#39;被选中
  6. 观察到:选择了其他行
  7. 注意:滚动时,会再次取消选择其他行。

1 个答案:

答案 0 :(得分:0)

我添加了这样的东西,它起作用了:

beforeSelectionChange: function() {
    var grid = angular.element('.ngGrid');
    grid.data('alreadySelectedItems', grid.scope().selectedItems);
    return true;
},
afterSelectionChange: function (rowItem) {
    if (rowItem.selected === true) {
    } else if (rowItem.selected === false) {
    } else if (rowItem.length > 0) {
        var selectedIds = [],
            grid = angular.element('.ngGrid'),
            renderedRows = grid.scope().renderedRows,
            alreadySelectedItems = grid.data('alreadySelectedItems') || [];
        angular.forEach(rowItem, function (row) {
            if (row.selected === true) {
                selectedIds.push(row.entity.Id);
            }
        });
        angular.forEach(renderedRows, function (row) {
            if (selectedIds.indexOf(row.entity.Id) === -1 && alreadySelectedItems.indexOf(row.entity) === -1) {
                row.selected = false;
            }
        });
        grid.removeData('alreadySelectedItems');
    }
}