mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
AAE-23099 Reset datatable selection on multiselect change to false (#9797)
This commit is contained in:
@@ -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', () => {
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user