Skip to content

Commit c6ce8c8

Browse files
committed
fix(grid): return the new rowSelection in correct order
1 parent b61eaad commit c6ce8c8

File tree

4 files changed

+73
-15
lines changed

4 files changed

+73
-15
lines changed

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,66 @@ describe('IgxGrid - Row Selection #grid', () => {
289289
expect(grid.rowSelectionChanging.emit).toHaveBeenCalledWith(args);
290290
});
291291

292+
it('Should display the newly selected rows in correct order', () => {
293+
const firstRow = grid.gridAPI.get_row_by_index(0);
294+
const secondRow = grid.gridAPI.get_row_by_index(1);
295+
const thirdRow = grid.gridAPI.get_row_by_index(2);
296+
spyOn(grid.rowSelectionChanging, 'emit').and.callThrough();
297+
298+
GridSelectionFunctions.clickRowCheckbox(thirdRow);
299+
fix.detectChanges();
300+
301+
expect(grid.rowSelectionChanging.emit).toHaveBeenCalledTimes(1);
302+
let args: IRowSelectionEventArgs = {
303+
added: [gridData[2]],
304+
cancel: false,
305+
event: jasmine.anything() as any,
306+
newSelection: [gridData[2]],
307+
oldSelection: [],
308+
removed: [],
309+
allRowsSelected: false,
310+
owner: grid
311+
};
312+
expect(grid.rowSelectionChanging.emit).toHaveBeenCalledWith(args);
313+
314+
GridSelectionFunctions.clickRowCheckbox(firstRow);
315+
fix.detectChanges();
316+
317+
expect(grid.rowSelectionChanging.emit).toHaveBeenCalledTimes(2);
318+
args = {
319+
added: [gridData[0]],
320+
cancel: false,
321+
event: jasmine.anything() as any,
322+
newSelection: [gridData[2], gridData[0]],
323+
oldSelection: [gridData[2]],
324+
removed: [],
325+
allRowsSelected: false,
326+
owner: grid
327+
};
328+
expect(grid.rowSelectionChanging.emit).toHaveBeenCalledWith(args);
329+
330+
GridSelectionFunctions.clickRowCheckbox(secondRow);
331+
fix.detectChanges();
332+
333+
expect(grid.rowSelectionChanging.emit).toHaveBeenCalledTimes(3);
334+
args = {
335+
added: [gridData[1]],
336+
cancel: false,
337+
event: jasmine.anything() as any,
338+
newSelection: [gridData[2], gridData[0], gridData[1]],
339+
oldSelection: [gridData[2], gridData[0]],
340+
removed: [],
341+
allRowsSelected: false,
342+
owner: grid
343+
};
344+
expect(grid.rowSelectionChanging.emit).toHaveBeenCalledWith(args);
345+
346+
expect(grid.selectedRows.length).toEqual(3);
347+
GridSelectionFunctions.verifyRowSelected(firstRow);
348+
GridSelectionFunctions.verifyRowSelected(secondRow);
349+
GridSelectionFunctions.verifyRowSelected(thirdRow);
350+
});
351+
292352
it('Should select the row with mouse click ', () => {
293353
expect(grid.selectRowOnClick).toBe(true);
294354
spyOn(grid.rowSelectionChanging, 'emit').and.callThrough();

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { EventEmitter, Injectable, NgZone } from '@angular/core';
22
import { Subject } from 'rxjs';
33
import { PlatformUtil } from '../../core/utils';
44
import { FilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree';
5-
import { GridPagingMode } from '../common/enums';
65
import { IRowSelectionEventArgs } from '../common/events';
76
import { GridType } from '../common/grid.interface';
87
import {
@@ -397,20 +396,17 @@ export class IgxGridSelectionService {
397396
return keys.some(k => this.isPivotRowSelected(k));
398397
});
399398
}
400-
if(this.rowSelection.size && (this.grid as any).totalItemCount || this.grid.pagingMode === GridPagingMode.Remote) {
401-
if(!this.grid.primaryKey) {
402-
return Array.from(this.rowSelection);
403-
}
404-
const selection = [];
405-
this.rowSelection.forEach(rID => {
406-
const rData = this.grid.gridAPI.get_all_data(true).find(row => this.getRecordKey(row) === rID);
407-
const partialRowData = {};
408-
partialRowData[this.grid.primaryKey] = rID;
409-
selection.push(rData ? rData : partialRowData);
410-
});
411-
return selection;
412-
}
413-
return this.rowSelection.size ? this.grid.gridAPI.get_all_data(true).filter(row => this.rowSelection.has(this.getRecordKey(row))) : [];
399+
if (!this.grid.primaryKey) {
400+
return Array.from(this.rowSelection);
401+
}
402+
const selection = [];
403+
this.rowSelection.forEach(rID => {
404+
const rData = this.grid.gridAPI.get_all_data(true).find(row => this.getRecordKey(row) === rID);
405+
const partialRowData = {};
406+
partialRowData[this.grid.primaryKey] = rID;
407+
selection.push(rData ? rData : partialRowData);
408+
});
409+
return selection;
414410
}
415411

416412
/** Returns array of the selected row id's. */

src/app/grid-remote-paging/grid-remote-paging.sample.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { GridPagingMode, IgxButtonDirective, IgxCardComponent, IgxCardContentDir
99
@Component({
1010
selector: 'app-grid-remote-paging-sample',
1111
templateUrl: 'grid-remote-paging.sample.html',
12+
providers: [RemoteService],
1213
standalone: true,
1314
imports: [IgxGridComponent, IgxColumnComponent, NgIf, IgxPaginatorComponent, IgxCardComponent, IgxCardHeaderComponent, IgxCardHeaderTitleDirective, IgxCardContentDirective, IgxButtonDirective, IgxSelectComponent, FormsModule, NgFor, IgxSelectItemComponent, AsyncPipe]
1415
})

src/app/grid-remote-virtualization/grid-remote-virtualization.sample.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { IgxButtonDirective, IgxGridComponent } from 'igniteui-angular';
77
@Component({
88
selector: 'app-grid-remote-virtualization-sample',
99
templateUrl: 'grid-remote-virtualization.sample.html',
10+
providers: [RemoteService],
1011
standalone: true,
1112
imports: [IgxGridComponent, IgxButtonDirective, AsyncPipe]
1213
})

0 commit comments

Comments
 (0)