Skip to content

Commit 8216171

Browse files
fix(grid): Correct shift-click selection in grouped IgxGrid #13757 (#13823)
* fix(grid): Correct shift-click selection in grouped IgxGrid * style(grid): Removing whitespaces and formating --------- Co-authored-by: Desislava Dincheva <[email protected]>
1 parent 94e9533 commit 8216171

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

projects/igniteui-angular/src/lib/grids/grid/grid-row-selection.spec.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,53 @@ describe('IgxGrid - Row Selection #grid', () => {
543543
}
544544
});
545545

546+
it('Should select the correct rows with Shift + Click when grouping is activated', () => {
547+
expect(grid.selectRowOnClick).toBe(true);
548+
spyOn(grid.rowSelectionChanging, 'emit').and.callThrough();
549+
550+
grid.groupBy({
551+
fieldName: 'ProductName', dir: SortingDirection.Desc, ignoreCase: false
552+
});
553+
554+
fix.detectChanges();
555+
556+
const firstGroupRow = grid.gridAPI.get_row_by_index(1);
557+
const lastGroupRow = grid.gridAPI.get_row_by_index(4);
558+
559+
// Clicking on the first row within a group
560+
UIInteractions.simulateClickEvent(firstGroupRow.nativeElement);
561+
fix.detectChanges();
562+
563+
GridSelectionFunctions.verifyRowSelected(firstGroupRow);
564+
565+
// Simulate Shift+Click on a row within another group
566+
const mockEvent = new MouseEvent('click', { shiftKey: true });
567+
lastGroupRow.nativeElement.dispatchEvent(mockEvent);
568+
fix.detectChanges();
569+
570+
expect(grid.selectedRows).toEqual([5, 14, 8]); // ids
571+
expect(grid.rowSelectionChanging.emit).toHaveBeenCalledTimes(2);
572+
expect(grid.rowSelectionChanging.emit).toHaveBeenCalledWith({
573+
added: [grid.dataView[2], grid.dataView[4]],
574+
cancel: false,
575+
event: jasmine.anything(),
576+
newSelection: [grid.dataView[1], grid.dataView[2], grid.dataView[4]],
577+
oldSelection: [grid.dataView[1]],
578+
removed: [],
579+
allRowsSelected: false,
580+
owner: grid
581+
});
582+
583+
const expectedSelectedRowIds = [5, 14, 8];
584+
grid.dataView.forEach((rowData, index) => {
585+
if (expectedSelectedRowIds.includes(rowData.ProductID)) {
586+
const row = grid.gridAPI.get_row_by_index(index);
587+
GridSelectionFunctions.verifyRowSelected(row);
588+
}
589+
});
590+
591+
});
592+
546593
it('Should NOT select multiple rows with Shift + Click when selectRowOnClick has false value', () => {
547594
grid.selectRowOnClick = false;
548595
spyOn(grid.rowSelectionChanging, 'emit').and.callThrough();

projects/igniteui-angular/src/lib/grids/selection/selection.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ export class IgxGridSelectionService {
689689
/** Returns all data in the grid, with applied filtering and sorting and without deleted rows. */
690690
public get allData(): Array<any> {
691691
let allData;
692-
if (this.isFilteringApplied() || this.grid.sortingExpressions.length) {
692+
if (this.isFilteringApplied() || this.grid.sortingExpressions.length || this.grid.groupingExpressions?.length) {
693693
allData = this.grid.pinnedRecordsCount ? this.grid._filteredSortedUnpinnedData : this.grid.filteredSortedData;
694694
} else {
695695
allData = this.grid.gridAPI.get_all_data(true);

0 commit comments

Comments
 (0)