[ADF-1134] selection management fixes (#2109)

* selection management fixes

* remove dual behaviour
This commit is contained in:
Denys Vuika
2017-07-20 17:43:55 +01:00
committed by Eugenio Romano
parent 0b9ab68f22
commit 96557e5f6b
2 changed files with 24 additions and 21 deletions

View File

@@ -147,6 +147,7 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck
if (changes.selectionMode && !changes.selectionMode.isFirstChange()) {
this.resetSelection();
this.emitRowSelectionEvent('row-unselect', null);
}
}
@@ -244,20 +245,12 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck
if (row) {
if (this.data) {
const newValue = !row.isSelected;
const domEventName = newValue ? 'row-select' : 'row-unselect';
const domEvent = new CustomEvent(domEventName, {
detail: {
row: row,
selection: this.selection
},
bubbles: true
});
if (this.isSingleSelectionMode()) {
this.resetSelection();
this.selectRow(row, newValue);
this.elementRef.nativeElement.dispatchEvent(domEvent);
this.emitRowSelectionEvent(domEventName, row);
}
if (this.isMultiSelectionMode()) {
@@ -266,7 +259,7 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck
this.resetSelection();
}
this.selectRow(row, newValue);
this.elementRef.nativeElement.dispatchEvent(domEvent);
this.emitRowSelectionEvent(domEventName, row);
}
}
@@ -315,6 +308,11 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck
this.selectRow(rows[i], e.checked);
}
}
const domEventName = e.checked ? 'row-select' : 'row-unselect';
const row = this.selection.length > 0 ? this.selection[0] : null;
this.emitRowSelectionEvent(domEventName, row);
}
}
@@ -324,15 +322,7 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck
this.selectRow(row, newValue);
const domEventName = newValue ? 'row-select' : 'row-unselect';
const domEvent = new CustomEvent(domEventName, {
detail: {
row: row,
selection: this.selection
},
bubbles: true
});
this.elementRef.nativeElement.dispatchEvent(domEvent);
this.emitRowSelectionEvent(domEventName, row);
}
onImageLoadingError(event: Event) {
@@ -428,4 +418,15 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck
}
}
}
private emitRowSelectionEvent(name: string, row: DataRow) {
const domEvent = new CustomEvent(name, {
detail: {
row: row,
selection: this.selection
},
bubbles: true
});
this.elementRef.nativeElement.dispatchEvent(domEvent);
}
}

View File

@@ -511,7 +511,8 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
detail: {
node: event.row.node,
selection: this.selection
}
},
bubbles: true
});
this.elementRef.nativeElement.dispatchEvent(domEvent);
}
@@ -522,7 +523,8 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
detail: {
node: event.row.node,
selection: this.selection
}
},
bubbles: true
});
this.elementRef.nativeElement.dispatchEvent(domEvent);
}