[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 f74c5306ca
commit 375d0782ee
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);
}
}
@@ -245,20 +246,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()) {
@@ -267,7 +260,7 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck
this.resetSelection();
}
this.selectRow(row, newValue);
this.elementRef.nativeElement.dispatchEvent(domEvent);
this.emitRowSelectionEvent(domEventName, row);
}
}
@@ -316,6 +309,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);
}
}
@@ -325,15 +323,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) {
@@ -429,4 +419,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);
}