From f3d2a7f1019d269df567047be901e07523cefcb4 Mon Sep 17 00:00:00 2001 From: Yonatan Alon Date: Fri, 2 Feb 2018 01:03:20 +0200 Subject: [PATCH] fix(selection.js): Allow selection in tables that use grouping (#6556) Modified the GridRow to default the isSelected flag to false fix #3911, fix #6126, fix #6145, fix #6263, fix #6398 --- src/features/selection/js/selection.js | 125 ++++++++++++++---- .../test/uiGridSelectionService.spec.js | 18 +-- src/js/core/factories/GridRow.js | 45 ++++--- 3 files changed, 132 insertions(+), 56 deletions(-) diff --git a/src/features/selection/js/selection.js b/src/features/selection/js/selection.js index 99fe2a35e0..4973c667ec 100644 --- a/src/features/selection/js/selection.js +++ b/src/features/selection/js/selection.js @@ -208,6 +208,23 @@ service.toggleRowSelection(grid, row, evt, grid.options.multiSelect, grid.options.noUnselect); } }, + /** + * @ngdoc function + * @name unSelectRowByVisibleIndex + * @methodOf ui.grid.selection.api:PublicApi + * @description Unselect the specified row by visible index (i.e. if you + * specify row 0 you'll get the first visible row unselected). In this context + * visible means of those rows that are theoretically visible (i.e. not filtered), + * rather than rows currently rendered on the screen. + * @param {number} index index within the rowsVisible array + * @param {Event} event object if raised from an event + */ + unSelectRowByVisibleIndex: function (rowNum, evt) { + var row = grid.renderContainers.body.visibleRowCache[rowNum]; + if (row !== null && typeof (row) !== 'undefined' && row.isSelected) { + service.toggleRowSelection(grid, row, evt, grid.options.multiSelect, grid.options.noUnselect); + } + }, /** * @ngdoc function * @name selectAllRows @@ -238,26 +255,32 @@ * @param {Event} event object if raised from an event */ selectAllVisibleRows: function (evt) { - if (grid.options.multiSelect === false) { - return; - } - - var changedRows = []; - grid.rows.forEach(function (row) { - if (row.visible) { - if (!row.isSelected && row.enableSelection !== false) { - row.setSelected(true); - service.decideRaiseSelectionEvent(grid, row, changedRows, evt); - } + if (grid.options.multiSelect !== false) { + var changedRows = []; + var rowCache = []; + if (grid.treeBase && grid.treeBase.tree) { + rowCache = getAllTreeRows(grid.treeBase.tree); } else { - if (row.isSelected) { - row.setSelected(false); - service.decideRaiseSelectionEvent(grid, row, changedRows, evt); + rowCache = grid.rows; + } + + for (var i = 0; i