Skip to content

Commit

Permalink
fix(Grid.js): Select All button should be disabled when no data is pr…
Browse files Browse the repository at this point in the history
…esent.

Ensuring Select All button is disabled by default when no data is present.

fix #6582
  • Loading branch information
Portugal, Marcelo authored and mportuga committed Mar 22, 2018
1 parent 713d3ea commit 08ec049
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/js/core/factories/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ angular.module('ui.grid')
}
});

if (self.selection) {
if (self.selection && self.rows.length) {
self.selection.selectAll = allRowsSelected;
}

Expand Down
33 changes: 33 additions & 0 deletions test/unit/core/factories/Grid.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,39 @@ describe('Grid factory', function () {
});
});

describe('selection', function() {
var grid;

beforeEach(function() {
grid = new Grid({ id: 1, enableRowHashing: false });
spyOn(grid, 'getRow').and.callFake(function(newEntity) {
return newEntity;
});

grid.rows = [];
grid.selection = {selectAll: false};
});
afterEach(function() {
grid.getRow.calls.reset();
});

it('should enable selectAll if a new row is added that is already selected', function() {
grid.modifyRows([{isSelected: true}]);

expect(grid.selection.selectAll).toBe(true);
});
it('should disable selectAll if a new row is added that is not selected', function() {
grid.modifyRows([{isSelected: false}]);

expect(grid.selection.selectAll).toBe(false);
});
it('should not update selectAll if there are no rows', function() {
grid.modifyRows([]);

expect(grid.selection.selectAll).toBe(false);
});
});

describe('follow source array', function() {
var dataRows, grid;

Expand Down

0 comments on commit 08ec049

Please sign in to comment.