Skip to content

Commit 08ec049

Browse files
Portugal, Marcelomportuga
Portugal, Marcelo
authored andcommitted
fix(Grid.js): Select All button should be disabled when no data is present.
Ensuring Select All button is disabled by default when no data is present. fix #6582
1 parent 713d3ea commit 08ec049

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/js/core/factories/Grid.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ angular.module('ui.grid')
11801180
}
11811181
});
11821182

1183-
if (self.selection) {
1183+
if (self.selection && self.rows.length) {
11841184
self.selection.selectAll = allRowsSelected;
11851185
}
11861186

test/unit/core/factories/Grid.spec.js

+33
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,39 @@ describe('Grid factory', function () {
530530
});
531531
});
532532

533+
describe('selection', function() {
534+
var grid;
535+
536+
beforeEach(function() {
537+
grid = new Grid({ id: 1, enableRowHashing: false });
538+
spyOn(grid, 'getRow').and.callFake(function(newEntity) {
539+
return newEntity;
540+
});
541+
542+
grid.rows = [];
543+
grid.selection = {selectAll: false};
544+
});
545+
afterEach(function() {
546+
grid.getRow.calls.reset();
547+
});
548+
549+
it('should enable selectAll if a new row is added that is already selected', function() {
550+
grid.modifyRows([{isSelected: true}]);
551+
552+
expect(grid.selection.selectAll).toBe(true);
553+
});
554+
it('should disable selectAll if a new row is added that is not selected', function() {
555+
grid.modifyRows([{isSelected: false}]);
556+
557+
expect(grid.selection.selectAll).toBe(false);
558+
});
559+
it('should not update selectAll if there are no rows', function() {
560+
grid.modifyRows([]);
561+
562+
expect(grid.selection.selectAll).toBe(false);
563+
});
564+
});
565+
533566
describe('follow source array', function() {
534567
var dataRows, grid;
535568

0 commit comments

Comments
 (0)