|
326 | 326 | * @ngdoc function
|
327 | 327 | * @name getSelectedRows
|
328 | 328 | * @methodOf ui.grid.selection.api:PublicApi
|
329 |
| - * @description returns all selectedRow's entity references |
| 329 | + * @description returns all selected Row's entity references |
330 | 330 | */
|
331 | 331 | 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)); |
337 | 342 | },
|
338 | 343 | /**
|
339 | 344 | * @ngdoc function
|
|
344 | 349 | getSelectedGridRows: function () {
|
345 | 350 | return service.getSelectedRows(grid);
|
346 | 351 | },
|
| 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 | + }, |
347 | 361 | /**
|
348 | 362 | * @ngdoc function
|
349 | 363 | * @name getSelectedCount
|
|
615 | 629 | return row.isSelected;
|
616 | 630 | });
|
617 | 631 | },
|
| 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 | + }, |
618 | 666 |
|
619 | 667 | /**
|
620 | 668 | * @ngdoc function
|
|
0 commit comments