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);
|
expect(dataSort).toEqual(dataSortObj);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reset selection on mode change', () => {
|
describe('Selection reset', () => {
|
||||||
spyOn(dataTable, 'resetSelection').and.callThrough();
|
beforeEach(() => {
|
||||||
|
spyOn(dataTable, 'resetSelection').and.callThrough();
|
||||||
|
|
||||||
dataTable.data = new ObjectDataTableAdapter([{ name: '1' }, { name: '2' }], [new ObjectDataColumn({ key: 'name' })]);
|
dataTable.data = new ObjectDataTableAdapter([{ name: '1' }, { name: '2' }], [new ObjectDataColumn({ key: 'name' })]);
|
||||||
const rows = dataTable.data.getRows();
|
const rows = dataTable.data.getRows();
|
||||||
rows[0].isSelected = true;
|
|
||||||
rows[1].isSelected = true;
|
|
||||||
|
|
||||||
expect(rows[0].isSelected).toBeTruthy();
|
rows[0].isSelected = true;
|
||||||
expect(rows[1].isSelected).toBeTruthy();
|
rows[1].isSelected = true;
|
||||||
|
|
||||||
dataTable.ngOnChanges({
|
expect(rows[0].isSelected).toBeTruthy();
|
||||||
selectionMode: new SimpleChange(null, 'multiple', false)
|
expect(rows[1].isSelected).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(dataTable.resetSelection).toHaveBeenCalled();
|
it('should reset selection on mode change', () => {
|
||||||
|
dataTable.ngOnChanges({
|
||||||
|
selectionMode: new SimpleChange(null, 'multiple', false)
|
||||||
|
});
|
||||||
|
|
||||||
|
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', () => {
|
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 dataChanges = changes['data'];
|
||||||
const rowChanges = changes['rows'];
|
const rowChanges = changes['rows'];
|
||||||
const columnChanges = changes['columns'];
|
const columnChanges = changes['columns'];
|
||||||
|
const multiselectChanges = changes['multiselect'];
|
||||||
|
|
||||||
if (this.isPropertyChanged(dataChanges) || this.isPropertyChanged(rowChanges) || this.isPropertyChanged(columnChanges)) {
|
if (this.isPropertyChanged(dataChanges) || this.isPropertyChanged(rowChanges) || this.isPropertyChanged(columnChanges)) {
|
||||||
if (this.isTableEmpty()) {
|
if (this.isTableEmpty()) {
|
||||||
@@ -333,6 +334,10 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges,
|
|||||||
if (this.isPropertyChanged(changes['sorting'])) {
|
if (this.isPropertyChanged(changes['sorting'])) {
|
||||||
this.setTableSorting(changes['sorting'].currentValue);
|
this.setTableSorting(changes['sorting'].currentValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (multiselectChanges?.currentValue === false) {
|
||||||
|
this.resetSelection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isColumnSortActive(column: DataColumn): boolean {
|
isColumnSortActive(column: DataColumn): boolean {
|
||||||
|
Reference in New Issue
Block a user