From 6b33edee911f66ad4c7f8af779306a6fa576b8b6 Mon Sep 17 00:00:00 2001 From: Anthony Date: Sat, 1 Oct 2016 19:17:07 +1000 Subject: [PATCH] Add row double click option --- src/components/body/body.component.ts | 6 ++++-- src/demos/virtual.ts | 4 ++++ src/types/click.type.ts | 4 ++++ src/types/index.ts | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 src/types/click.type.ts diff --git a/src/components/body/body.component.ts b/src/components/body/body.component.ts index b4778015f..7ee915135 100644 --- a/src/components/body/body.component.ts +++ b/src/components/body/body.component.ts @@ -13,7 +13,7 @@ import { import { Subscription } from 'rxjs/Subscription'; import { Keys, selectRows, selectRowsBetween, translateXY } from '../../utils'; import { StateService } from '../../services'; -import { SelectionType } from '../../types'; +import { SelectionType, ClickType } from '../../types'; import { Scroller } from '../../directives'; @Component({ @@ -38,6 +38,7 @@ import { Scroller } from '../../directives'; *ngFor="let row of rows; let i = index; trackBy: trackRowBy" [attr.tabindex]="i" (click)="rowClicked($event, i, row)" + (dblclick)="rowClicked($event, i, row)" (keydown)="rowKeydown($event, i, row)" [row]="row" [class.datatable-row-even]="row.$$index % 2 === 0" @@ -190,7 +191,8 @@ export class DataTableBody implements OnInit, OnDestroy { } rowClicked(event, index, row): void { - this.onRowClick.emit({event, row}); + let clickType = event.type === 'dblclick' ? ClickType.double : ClickType.single; + this.onRowClick.emit({ type: clickType, event, row }); this.selectRow(event, index, row); } diff --git a/src/demos/virtual.ts b/src/demos/virtual.ts index a02aa804e..bbfc24d70 100644 --- a/src/demos/virtual.ts +++ b/src/demos/virtual.ts @@ -12,6 +12,7 @@ import '../themes/material.scss'; class='material' [rows]='rows' (onPageChange)="paged($event)" + (onRowClick)="rowClick($event)" [options]='options'> @@ -71,4 +72,7 @@ export class App { req.send(); } + rowClick(args) { + console.log('rowClick', args); + } } diff --git a/src/types/click.type.ts b/src/types/click.type.ts new file mode 100644 index 000000000..b7e15937d --- /dev/null +++ b/src/types/click.type.ts @@ -0,0 +1,4 @@ +export enum ClickType { + single = 'single' as any, + double = 'double' as any +} diff --git a/src/types/index.ts b/src/types/index.ts index 52d495e9c..125aaa088 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -2,3 +2,4 @@ export * from './column-mode.type'; export * from './sort.type'; export * from './sort-direction.type'; export * from './selection.type'; +export * from './click.type'; \ No newline at end of file