Skip to content

Commit

Permalink
Fixed #1347 - Row double click for DataTable
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Jun 17, 2021
1 parent e480bf4 commit 2543b0d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
21 changes: 21 additions & 0 deletions api-generator/components/datatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,27 @@ const DataTableEvents = [
}
]
},
{
name: "row-dblclick",
description: "Callback to invoke when a row is double clicked.",
arguments: [
{
name: "event.originalEvent",
type: "object",
description: "Browser event."
},
{
name: "event.data",
type: "object",
description: "Selected row data."
},
{
name: "event.index",
type: "number",
description: "Row index"
}
]
},
{
name: "row-contextmenu",
description: "Callback to invoke when a row is selected with a ContextMenu",
Expand Down
1 change: 1 addition & 0 deletions src/components/datatable/DataTable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ declare class DataTable extends Vue {
$emit(eventName: 'sort', event: Event): this;
$emit(eventName: 'filter', event: Event): this;
$emit(eventName: 'row-click', event: Event): this;
$emit(eventName: 'row-dblclick', event: Event): this;
$emit(eventName: 'row-contextmenu', event: Event): this;
$emit(eventName: 'row-select', event: Event): this;
$emit(eventName: 'row-unselect', event: Event): this;
Expand Down
9 changes: 8 additions & 1 deletion src/components/datatable/DataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
:rowGroupMode="rowGroupMode" :groupRowsBy="groupRowsBy" :expandableRowGroups="expandableRowGroups" :rowClass="rowClass" :editMode="editMode" :compareSelectionBy="compareSelectionBy"
:expandedRowIcon="expandedRowIcon" :collapsedRowIcon="collapsedRowIcon" :expandedRows="expandedRows" :expandedRowKeys="d_expandedRowKeys" :expandedRowGroups="expandedRowGroups"
:editingRows="editingRows" :editingRowKeys="d_editingRowKeys" :templates="$scopedSlots" :loading="loading"
@rowgroup-toggle="toggleRowGroup" @row-click="onRowClick($event)" @row-rightclick="onRowRightClick($event)" @row-touchend="onRowTouchEnd" @row-keydown="onRowKeyDown"
@rowgroup-toggle="toggleRowGroup" @row-click="onRowClick($event)" @row-dblclick="onRowDblClick($event)" @row-rightclick="onRowRightClick($event)" @row-touchend="onRowTouchEnd" @row-keydown="onRowKeyDown"
@row-mousedown="onRowMouseDown" @row-dragstart="onRowDragStart($event)" @row-dragover="onRowDragOver($event)" @row-dragleave="onRowDragLeave($event)" @row-dragend="onRowDragEnd($event)" @row-drop="onRowDrop($event)"
@row-toggle="toggleRow($event)" @radio-change="toggleRowWithRadio($event)" @checkbox-change="toggleRowWithCheckbox($event)"
@cell-edit-init="onCellEditInit($event)" @cell-edit-complete="onCellEditComplete($event)" @cell-edit-cancel="onCellEditCancel($event)"
Expand Down Expand Up @@ -722,6 +722,13 @@ export default {
this.rowTouched = false;
},
onRowDblClick(e) {
const event = e.originalEvent;
if (DomHandler.isClickable(event.target)) {
return;
}
this.$emit('row-dblclick', e);
},
onRowRightClick(event) {
DomHandler.clearSelection();
event.originalEvent.target.focus();
Expand Down
6 changes: 5 additions & 1 deletion src/components/datatable/TableBody.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
</tr>
<tr :class="getRowClass(rowData)" :key="getRowKey(rowData, index)"
v-if="expandableRowGroups ? isRowGroupExpanded(rowData): true"
@click="onRowClick($event, rowData, index)" @contextmenu="onRowRightClick($event, rowData, index)" @touchend="onRowTouchEnd($event)" @keydown="onRowKeyDown($event, rowData, index)" :tabindex="selectionMode || contextMenu ? '0' : null"
@click="onRowClick($event, rowData, index)" @dblclick="onRowDblClick($event, rowData, index)" @contextmenu="onRowRightClick($event, rowData, index)" @touchend="onRowTouchEnd($event)"
@keydown="onRowKeyDown($event, rowData, index)" :tabindex="selectionMode || contextMenu ? '0' : null"
@mousedown="onRowMouseDown($event)" @dragstart="onRowDragStart($event, index)" @dragover="onRowDragOver($event,index)" @dragleave="onRowDragLeave($event)" @dragend="onRowDragEnd($event)" @drop="onRowDrop($event)">
<template v-for="(col,i) of columns">
<DTBodyCell v-if="shouldRenderBodyCell(value, col, index)" :key="col.columnKey||col.field||i" :rowData="rowData" :column="col" :index="index" :selected="isSelected(rowData)"
Expand Down Expand Up @@ -390,6 +391,9 @@ export default {
onRowClick(event, rowData, rowIndex) {
this.$emit('row-click', {originalEvent: event, data: rowData, index: rowIndex});
},
onRowDblClick(event, rowData, rowIndex) {
this.$emit('row-dblclick', {originalEvent: event, data: rowData, index: rowIndex});
},
onRowRightClick(event, rowData, rowIndex) {
this.$emit('row-rightclick', {originalEvent: event, data: rowData, index: rowIndex});
},
Expand Down
7 changes: 7 additions & 0 deletions src/views/datatable/DataTableDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2154,6 +2154,13 @@ export default {
event.index: Row index.</td>
<td>Callback to invoke when a row is clicked.</td>
</tr>
<tr>
<td>row-dblclick</td>
<td>event.originalEvent: Browser event. <br />
event.data: Selected row data. <br />
event.index: Row index.</td>
<td>Callback to invoke when a row is double clicked.</td>
</tr>
<tr>
<td>row-contextmenu</td>
<td>event.originalEvent: Browser event. <br />
Expand Down

0 comments on commit 2543b0d

Please sign in to comment.