Skip to content

Commit

Permalink
Fixed #5256
Browse files Browse the repository at this point in the history
  • Loading branch information
Çağatay Çivici authored and Çağatay Çivici committed Mar 4, 2018
1 parent 08620c4 commit 7b00bd4
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
60 changes: 58 additions & 2 deletions src/app/components/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1973,6 +1973,62 @@ export class SelectableRow implements OnInit, OnDestroy {

}

@Directive({
selector: '[pSelectableRowDblClick]',
providers: [DomHandler],
host: {
'[class.ui-state-highlight]': 'selected'
}
})
export class SelectableRowDblClick implements OnInit, OnDestroy {

@Input("pSelectableRowDblClick") data: any;

@Input("pSelectableRowIndex") index: number;

@Input() pSelectableRowDisabled: boolean;

selected: boolean;

subscription: Subscription;

constructor(public dt: Table, public domHandler: DomHandler, public tableService: TableService) {
if (this.isEnabled()) {
this.subscription = this.dt.tableService.selectionSource$.subscribe(() => {
this.selected = this.dt.isSelected(this.data);
});
}
}

ngOnInit() {
if (this.isEnabled()) {
this.selected = this.dt.isSelected(this.data);
}
}

@HostListener('dblclick', ['$event'])
onClick(event: Event) {
if (this.isEnabled()) {
this.dt.handleRowClick({
originalEvent: event,
rowData: this.data,
rowIndex: this.index
});
}
}

isEnabled() {
return this.pSelectableRowDisabled !== false;
}

ngOnDestroy() {
if (this.subscription) {
this.subscription.unsubscribe();
}
}

}

@Directive({
selector: '[pContextMenuRow]',
host: {
Expand Down Expand Up @@ -2753,7 +2809,7 @@ export class ReorderableRow implements AfterViewInit {

@NgModule({
imports: [CommonModule,PaginatorModule],
exports: [Table,SharedModule,SortableColumn,SelectableRow,RowToggler,ContextMenuRow,ResizableColumn,ReorderableColumn,EditableColumn,CellEditor,SortIcon,TableRadioButton,TableCheckbox,TableHeaderCheckbox,ReorderableRowHandle,ReorderableRow],
declarations: [Table,SortableColumn,SelectableRow,RowToggler,ContextMenuRow,ResizableColumn,ReorderableColumn,EditableColumn,CellEditor,TableBody,ScrollableView,SortIcon,TableRadioButton,TableCheckbox,TableHeaderCheckbox,ReorderableRowHandle,ReorderableRow]
exports: [Table,SharedModule,SortableColumn,SelectableRow,RowToggler,ContextMenuRow,ResizableColumn,ReorderableColumn,EditableColumn,CellEditor,SortIcon,TableRadioButton,TableCheckbox,TableHeaderCheckbox,ReorderableRowHandle,ReorderableRow,SelectableRowDblClick],
declarations: [Table,SortableColumn,SelectableRow,RowToggler,ContextMenuRow,ResizableColumn,ReorderableColumn,EditableColumn,CellEditor,TableBody,ScrollableView,SortIcon,TableRadioButton,TableCheckbox,TableHeaderCheckbox,ReorderableRowHandle,ReorderableRow,SelectableRowDblClick]
})
export class TableModule { }
5 changes: 4 additions & 1 deletion src/app/showcase/components/table/tabledemo.html
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,10 @@ <h3>Filtering</h3>
<h3>Selection</h3>
<p>Table provides built-in single and multiple selection features where selected rows are bound to the selection property and onRowSelect-onRowUnselect events
are provided as optional callbacks. In order to enable this feature, define a selectionMode, bind a selection reference and add pSelectableRow directive
whose value is the rowData to the rows that can be selected. Alternatively instead of row click, radiobutton or checkbox elements can be used to implement row selection.</p>
whose value is the rowData to the rows that can be selected. If you prefer double click use pSelectableRowDblClick directive instead. In both cases optional
pSelectableRowIndex property is avaiable to access the row index.</p>

<p>Alternatively instead of row click, radiobutton or checkbox elements can be used to implement row selection.</p>

<p>When resolving if a row is selected, by default Table compares selection array with the datasource which may cause a performance issue with huge datasets that do not use pagination.
If available the fastest way is to use dataKey property that identifies a unique row so that Table can avoid comparing arrays as internally a map instance is used instead of looping arrays, on the other hand
Expand Down

0 comments on commit 7b00bd4

Please sign in to comment.