Skip to content

Commit

Permalink
Merge pull request #14806 from IgniteUI/mkirkova/fix-14724-17.2.x
Browse files Browse the repository at this point in the history
Clear selected rows correctly when a row is updated and filtering is applied - 17.2.x
  • Loading branch information
kacheshmarova authored Sep 27, 2024
2 parents 818aa7b + 7f24f9c commit 8b6bfd1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TestBed, fakeAsync, tick, waitForAsync, ComponentFixture } from '@angul
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { IgxGridComponent } from './grid.component';
import { wait, UIInteractions } from '../../test-utils/ui-interactions.spec';
import { IgxStringFilteringOperand, IgxNumberFilteringOperand } from '../../data-operations/filtering-condition';
import { IgxStringFilteringOperand, IgxNumberFilteringOperand, IgxBooleanFilteringOperand } from '../../data-operations/filtering-condition';
import { configureTestSuite } from '../../test-utils/configure-suite';
import {
RowSelectionComponent,
Expand Down Expand Up @@ -2139,6 +2139,27 @@ describe('IgxGrid - Row Selection #grid', () => {
GridSelectionFunctions.verifyHeaderRowCheckboxState(fix, true, false);
expect(grid.selectedRows.length).toBe(grid.data.length);
});

it('Should deselect updated row with header checkbox when batchEditing is enbaled and filtering is applied', () => {
grid.batchEditing = true;
grid.selectRows([1]);
grid.filter('InStock', null, IgxBooleanFilteringOperand.instance().condition('true'));
fix.detectChanges();

const row = grid.gridAPI.get_row_by_index(0);
GridSelectionFunctions.verifyRowSelected(row);

grid.updateRow({ ProductID: 1, ProductName: 'test', InStock: true, UnitsInStock: 1, OrderDate: new Date('2019-03-01') }, 1);
fix.detectChanges();

GridSelectionFunctions.clickHeaderRowCheckbox(fix);
fix.detectChanges();
GridSelectionFunctions.verifyRowSelected(row);

GridSelectionFunctions.clickHeaderRowCheckbox(fix);
fix.detectChanges();
GridSelectionFunctions.verifyRowSelected(row, false);
});
});

describe('Integration with CRUD and transactions', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,14 @@ export class IgxGridSelectionService {
const selectedRows = this.getSelectedRowsData();
const removedRec = this.isFilteringApplied() ?
this.allData.filter(row => this.isRowSelected(this.getRecordKey(row))) : selectedRows;
const newSelection = this.isFilteringApplied() ? selectedRows.filter(x => !removedRec.includes(x)) : [];
let newSelection;
if (this.grid.primaryKey) {
newSelection = this.isFilteringApplied() ? selectedRows.filter(x => {
return !removedRec.some(item => item[this.grid.primaryKey] === x[this.grid.primaryKey]);
}) : [];
} else {
newSelection = this.isFilteringApplied() ? selectedRows.filter(x => !removedRec.includes(x)) : [];
}
this.emitRowSelectionEvent(newSelection, [], removedRec, event, selectedRows);
}

Expand Down

0 comments on commit 8b6bfd1

Please sign in to comment.