Skip to content

Commit 31bab77

Browse files
prx-lmomportuga
authored andcommitted
[feature/4850]
- added get unselectedRows Api
1 parent 9031069 commit 31bab77

File tree

1 file changed

+54
-6
lines changed

1 file changed

+54
-6
lines changed

packages/selection/src/js/selection.js

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,19 @@
326326
* @ngdoc function
327327
* @name getSelectedRows
328328
* @methodOf ui.grid.selection.api:PublicApi
329-
* @description returns all selectedRow's entity references
329+
* @description returns all selected Row's entity references
330330
*/
331331
getSelectedRows: function () {
332-
return service.getSelectedRows(grid).map(function (gridRow) {
333-
return gridRow.entity;
334-
}).filter(function (entity) {
335-
return entity.hasOwnProperty('$$hashKey') || !angular.isObject(entity);
336-
});
332+
return service.mapAndFilterRowsByEntity(service.getSelectedRows(grid));
333+
},
334+
/**
335+
* @ngdoc function
336+
* @name getUnSelectedRows
337+
* @methodOf ui.grid.selection.api:PublicApi
338+
* @description returns all unselected Row's entity references
339+
*/
340+
getUnSelectedRows: function () {
341+
return service.mapAndFilterRowsByEntity(service.getUnSelectedRows(grid));
337342
},
338343
/**
339344
* @ngdoc function
@@ -344,6 +349,15 @@
344349
getSelectedGridRows: function () {
345350
return service.getSelectedRows(grid);
346351
},
352+
/**
353+
* @ngdoc function
354+
* @name getSelectedGridRows
355+
* @methodOf ui.grid.selection.api:PublicApi
356+
* @description returns all unselected Row's as gridRows
357+
*/
358+
getUnSelectedGridRows: function () {
359+
return service.getUnSelectedRows(grid);
360+
},
347361
/**
348362
* @ngdoc function
349363
* @name getSelectedCount
@@ -615,6 +629,40 @@
615629
return row.isSelected;
616630
});
617631
},
632+
/**
633+
* @ngdoc function
634+
* @name getUnSelectedRows
635+
* @methodOf ui.grid.selection.service:uiGridSelectionService
636+
* @description Returns all the unselected rows
637+
* @param {Grid} grid grid object
638+
*/
639+
getUnSelectedRows: function (grid) {
640+
return grid.rows.filter(function (row) {
641+
return !row.isSelected;
642+
});
643+
},
644+
/**
645+
* @ngdoc function
646+
* @name mapAndFilterRowsByEntity
647+
* @methodOf ui.grid.selection.service:uiGridSelectionService
648+
* @description Filters all rows by entity and then maps them to Array.
649+
*/
650+
mapAndFilterRowsByEntity: function(gridRows) {
651+
if(typeof gridRows.reduce === 'function') { // If reduce is available it will be taken, due to better performance
652+
return gridRows.reduce(function (previousVal, currentRow) {
653+
if (currentRow.entity.hasOwnProperty('$$hashKey') || !angular.isObject(currentRow.entity)) {
654+
previousVal.push(currentRow.entity);
655+
}
656+
return previousVal;
657+
}, []);
658+
}
659+
660+
return gridRows.filter(function (gridRow) { // stays as polyfill
661+
return gridRow.entity.hasOwnProperty('$$hashKey') || !angular.isObject(gridRow.entity);
662+
}).map(function (gridRow) {
663+
return gridRow.entity;
664+
});
665+
},
618666

619667
/**
620668
* @ngdoc function

0 commit comments

Comments
 (0)