Commit da55375f0082406c1a45e57eba2cde7d3694ab0c
1 parent
2b67801d
Added click and dblclick events to table
Showing
3 changed files
with
35 additions
and
5 deletions
Show diff stats
src/components/table/table-body.vue
... | ... | @@ -9,7 +9,8 @@ |
9 | 9 | :class="rowClasses(row._index)" |
10 | 10 | @mouseenter.stop="handleMouseIn(row._index)" |
11 | 11 | @mouseleave.stop="handleMouseOut(row._index)" |
12 | - @click.stop="highlightCurrentRow(row._index)"> | |
12 | + @click.stop="clickCurrentRow(row._index)" | |
13 | + @dblclick.stop="dblclickCurrentRow(row._index)"> | |
13 | 14 | <td v-for="column in columns" :class="alignCls(column)"> |
14 | 15 | <Cell |
15 | 16 | :fixed="fixed" |
... | ... | @@ -66,8 +67,11 @@ |
66 | 67 | handleMouseOut (_index) { |
67 | 68 | this.$parent.handleMouseOut(_index); |
68 | 69 | }, |
69 | - highlightCurrentRow (_index) { | |
70 | - this.$parent.highlightCurrentRow(_index); | |
70 | + clickCurrentRow (_index) { | |
71 | + this.$parent.clickCurrentRow(_index); | |
72 | + }, | |
73 | + dblclickCurrentRow (_index) { | |
74 | + this.$parent.dblclickCurrentRow(_index); | |
71 | 75 | } |
72 | 76 | } |
73 | 77 | }; | ... | ... |
src/components/table/table.vue
... | ... | @@ -297,6 +297,14 @@ |
297 | 297 | const oldData = oldIndex < 0 ? null : JSON.parse(JSON.stringify(this.data[oldIndex])); |
298 | 298 | this.$emit('on-current-change', JSON.parse(JSON.stringify(this.data[_index])), oldData); |
299 | 299 | }, |
300 | + clickCurrentRow (_index) { | |
301 | + this.highlightCurrentRow (_index); | |
302 | + this.$emit('on-click', JSON.parse(JSON.stringify(this.data[_index]))); | |
303 | + }, | |
304 | + dblclickCurrentRow (_index) { | |
305 | + this.highlightCurrentRow (_index); | |
306 | + this.$emit('on-dblclick', JSON.parse(JSON.stringify(this.data[_index]))); | |
307 | + }, | |
300 | 308 | getSelection () { |
301 | 309 | let selectionIndexes = []; |
302 | 310 | for (let i in this.objData) { | ... | ... |
test/routers/table.vue
1 | 1 | <template> |
2 | 2 | <i-button @click="changeFilter">改变filter</i-button> |
3 | + <span v-if="currentRow !== null">Current Row: {{currentRow.name}}</span> | |
3 | 4 | <Switch size="small" @on-change="switchCellEllipsis"></Switch> Ellipsis |
4 | - <i-table border :columns="columns6" :data="data5"></i-table> | |
5 | + <i-table | |
6 | + border | |
7 | + :columns="columns6" | |
8 | + :data="data5" | |
9 | + :highlight-row="true" | |
10 | + @on-current-change="onCurrentChange" | |
11 | + @on-dblclick="onDblclick"> | |
12 | + </i-table> | |
5 | 13 | </template> |
6 | 14 | <script> |
7 | 15 | export default { |
... | ... | @@ -99,7 +107,8 @@ |
99 | 107 | date: '2016-10-04', |
100 | 108 | longText: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' |
101 | 109 | } |
102 | - ] | |
110 | + ], | |
111 | + currentRow: null | |
103 | 112 | } |
104 | 113 | }, |
105 | 114 | methods: { |
... | ... | @@ -113,6 +122,15 @@ |
113 | 122 | }, |
114 | 123 | switchCellEllipsis (status) { |
115 | 124 | this.columns6[5].ellipsis = status |
125 | + }, | |
126 | + onClick (data) { | |
127 | + window.alert('Click ' + data.name) | |
128 | + }, | |
129 | + onCurrentChange (data) { | |
130 | + this.currentRow = data | |
131 | + }, | |
132 | + onDblclick (data) { | |
133 | + window.alert('Double Click ' + data.name) | |
116 | 134 | } |
117 | 135 | } |
118 | 136 | } | ... | ... |