AAE-23099 Reset datatable selection on multiselect change to false (#9797)

This commit is contained in:
Robert Duda
2024-06-19 13:56:32 +02:00
committed by GitHub
parent 32e2518c6a
commit 672f6347d0
2 changed files with 29 additions and 11 deletions

View File

@@ -397,22 +397,35 @@ describe('DataTable', () => {
expect(dataSort).toEqual(dataSortObj);
});
it('should reset selection on mode change', () => {
describe('Selection reset', () => {
beforeEach(() => {
spyOn(dataTable, 'resetSelection').and.callThrough();
dataTable.data = new ObjectDataTableAdapter([{ name: '1' }, { name: '2' }], [new ObjectDataColumn({ key: 'name' })]);
const rows = dataTable.data.getRows();
rows[0].isSelected = true;
rows[1].isSelected = true;
expect(rows[0].isSelected).toBeTruthy();
expect(rows[1].isSelected).toBeTruthy();
});
it('should reset selection on mode change', () => {
dataTable.ngOnChanges({
selectionMode: new SimpleChange(null, 'multiple', false)
});
expect(dataTable.resetSelection).toHaveBeenCalled();
expect(dataTable.selection).toEqual([]);
});
it('should reset selection on multiselect change', () => {
dataTable.ngOnChanges({
multiselect: new SimpleChange(true, false, false)
});
expect(dataTable.selection).toEqual([]);
});
});
it('should select the row where isSelected is true', () => {

View File

@@ -302,6 +302,7 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges,
const dataChanges = changes['data'];
const rowChanges = changes['rows'];
const columnChanges = changes['columns'];
const multiselectChanges = changes['multiselect'];
if (this.isPropertyChanged(dataChanges) || this.isPropertyChanged(rowChanges) || this.isPropertyChanged(columnChanges)) {
if (this.isTableEmpty()) {
@@ -333,6 +334,10 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges,
if (this.isPropertyChanged(changes['sorting'])) {
this.setTableSorting(changes['sorting'].currentValue);
}
if (multiselectChanges?.currentValue === false) {
this.resetSelection();
}
}
isColumnSortActive(column: DataColumn): boolean {