Skip to content

Commit

Permalink
fix(grid): Correct shift-click selection in grouped IgxGrid #13757 (#…
Browse files Browse the repository at this point in the history
…13785)

* fix(grid): Correct shift-click selection in grouped IgxGrid #13757

* fix(grid): Added conditional checks and enchanced comparison function

* fix(grid): Taking into account duplicate rows

* fix(grid): Fixed indexing on non-grouped selection

* fix(grid): Returned previous code and made a slight change

* fix(grid): Formated and cleared code

* fix(grid): Formated and cleared code

* fix(grid): Removed white spaces

* fix(grid): Removed white spaces

* fix(grid): Cleared package-lock.json

* test(grid): Added unit test for shift-click row selection with grouping

* style(grid): Removing whitespaces and formating

* style(grid): Correct minor typos

---------

Co-authored-by: Hristo <[email protected]>
Co-authored-by: Desislava Dincheva <[email protected]>
  • Loading branch information
3 people authored Jan 23, 2024
1 parent 4ffb58b commit 84be07c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,53 @@ describe('IgxGrid - Row Selection #grid', () => {
}
});

it('Should select the correct rows with Shift + Click when grouping is activated', () => {
expect(grid.selectRowOnClick).toBe(true);
spyOn(grid.rowSelectionChanging, 'emit').and.callThrough();

grid.groupBy({
fieldName: 'ProductName', dir: SortingDirection.Desc, ignoreCase: false
});

fix.detectChanges();

const firstGroupRow = grid.gridAPI.get_row_by_index(1);
const lastGroupRow = grid.gridAPI.get_row_by_index(4);

// Clicking on the first row within a group
UIInteractions.simulateClickEvent(firstGroupRow.nativeElement);
fix.detectChanges();

GridSelectionFunctions.verifyRowSelected(firstGroupRow);

// Simulate Shift+Click on a row within another group
const mockEvent = new MouseEvent('click', { shiftKey: true });
lastGroupRow.nativeElement.dispatchEvent(mockEvent);
fix.detectChanges();

expect(grid.selectedRows).toEqual([5, 14, 8]); // ids
expect(grid.rowSelectionChanging.emit).toHaveBeenCalledTimes(2);
expect(grid.rowSelectionChanging.emit).toHaveBeenCalledWith({
added: [grid.dataView[2], grid.dataView[4]],
cancel: false,
event: jasmine.anything(),
newSelection: [grid.dataView[1], grid.dataView[2], grid.dataView[4]],
oldSelection: [grid.dataView[1]],
removed: [],
allRowsSelected: false,
owner: grid
});

const expectedSelectedRowIds = [5, 14, 8];
grid.dataView.forEach((rowData, index) => {
if (expectedSelectedRowIds.includes(rowData.ProductID)) {
const row = grid.gridAPI.get_row_by_index(index);
GridSelectionFunctions.verifyRowSelected(row);
}
});

});

it('Should NOT select multiple rows with Shift + Click when selectRowOnClick has false value', () => {
grid.selectRowOnClick = false;
spyOn(grid.rowSelectionChanging, 'emit').and.callThrough();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,8 @@ export class IgxGridSelectionService {
/** Returns all data in the grid, with applied filtering and sorting and without deleted rows. */
public get allData(): Array<any> {
let allData;
if (this.isFilteringApplied() || this.grid.sortingExpressions.length) {
// V.T. Jan 17th, 2024 #13757 Adding an additional conditional check to take account WITHIN range of groups
if (this.isFilteringApplied() || this.grid.sortingExpressions.length || this.grid.groupingExpressions?.length) {
allData = this.grid.pinnedRecordsCount ? this.grid._filteredSortedUnpinnedData : this.grid.filteredSortedData;
} else {
allData = this.grid.gridAPI.get_all_data(true);
Expand Down

0 comments on commit 84be07c

Please sign in to comment.