[ADF-1714] added selection mechanism for enter key pressed on datatable (#3157)

This commit is contained in:
Vito
2018-04-09 16:07:16 +01:00
committed by Eugenio Romano
parent 89b56e9e66
commit bc979ad661
3 changed files with 74 additions and 20 deletions

View File

@@ -292,31 +292,40 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck
}
if (row) {
if (this.data) {
if (this.isSingleSelectionMode()) {
this.resetSelection();
this.selectRow(row, true);
this.emitRowSelectionEvent('row-select', row);
}
if (this.isMultiSelectionMode()) {
const modifier = e && (e.metaKey || e.ctrlKey);
const newValue = modifier ? !row.isSelected : true;
const domEventName = newValue ? 'row-select' : 'row-unselect';
if (!modifier) {
this.resetSelection();
}
this.selectRow(row, newValue);
this.emitRowSelectionEvent(domEventName, row);
}
}
this.handleRowSelection(row, e);
const dataRowEvent = new DataRowEvent(row, e, this);
this.clickObserver.next(dataRowEvent);
}
}
onEnterKeyPressed(row: DataRow, e: KeyboardEvent) {
if (row) {
this.handleRowSelection(row, e);
}
}
private handleRowSelection(row: DataRow, e: KeyboardEvent | MouseEvent) {
if (this.data) {
if (this.isSingleSelectionMode()) {
this.resetSelection();
this.selectRow(row, true);
this.emitRowSelectionEvent('row-select', row);
}
if (this.isMultiSelectionMode()) {
const modifier = e && (e.metaKey || e.ctrlKey);
const newValue = modifier ? !row.isSelected : true;
const domEventName = newValue ? 'row-select' : 'row-unselect';
if (!modifier) {
this.resetSelection();
}
this.selectRow(row, newValue);
this.emitRowSelectionEvent(domEventName, row);
}
}
}
resetSelection(): void {
if (this.data) {
const rows = this.data.getRows();