Skip to content

Commit 99beada

Browse files
committed
Add selection PublicApi method to expose selected count
1 parent 702e1b8 commit 99beada

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/features/selection/js/selection.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,15 @@
292292
getSelectedGridRows: function () {
293293
return service.getSelectedRows(grid);
294294
},
295+
/**
296+
* @ngdoc function
297+
* @name getSelectedCount
298+
* @methodOf ui.grid.selection.api:PublicApi
299+
* @description returns the number of rows selected
300+
*/
301+
getSelectedCount: function () {
302+
return grid.selection.selectedCount;
303+
},
295304
/**
296305
* @ngdoc function
297306
* @name setMultiSelect

src/features/selection/test/uiGridSelectionService.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ describe('ui.grid.selection uiGridSelectionService', function () {
8888
expect(uiGridSelectionService.getSelectedRows(grid).length).toBe(0);
8989
});
9090

91+
it('should update selectedCount', function () {
92+
uiGridSelectionService.toggleRowSelection(grid, grid.rows[0]);
93+
expect(grid.api.selection.getSelectedCount()).toBe(1);
94+
uiGridSelectionService.clearSelectedRows(grid);
95+
expect(grid.api.selection.getSelectedCount()).toBe(0);
96+
});
97+
9198
it('should utilize public apis', function () {
9299
grid.api.selection.toggleRowSelection(grid.rows[0].entity);
93100
expect(uiGridSelectionService.getSelectedRows(grid).length).toBe(1);

0 commit comments

Comments
 (0)