Table: Add handleEvent. (#3305)

This commit is contained in:
Cyril Su 2017-03-06 18:45:27 +08:00 committed by cinwell.li
parent 4aabc95a6d
commit 5e796ca33b
2 changed files with 10 additions and 18 deletions

View File

@ -219,37 +219,29 @@ export default {
},
handleContextMenu(event, row) {
const table = this.table;
const cell = getCell(event);
let column;
if (cell) {
column = getColumnByCell(table, cell);
if (column) {
table.$emit('cell-dblclick', row, column, cell, event);
}
}
table.$emit('row-contextmenu', row, event);
this.handleEvent(event, row, 'contextmenu');
},
handleDoubleClick(event, row) {
const table = this.table;
table.$emit('row-dblclick', row, event);
this.handleEvent(event, row, 'dblclick');
},
handleClick(event, row) {
this.store.commit('setCurrentRow', row);
this.handleEvent(event, row, 'click');
},
handleEvent(event, row, name) {
const table = this.table;
const cell = getCell(event);
let column;
if (cell) {
column = getColumnByCell(table, cell);
if (column) {
table.$emit('cell-click', row, column, cell, event);
table.$emit(`cell-${name}`, row, column, cell, event);
}
}
this.store.commit('setCurrentRow', row);
table.$emit('row-click', row, event, column);
table.$emit(`row-${name}`, row, event, column);
},
handleExpandClick(row) {

View File

@ -459,7 +459,7 @@ describe('Table', () => {
const cell = vm.$el.querySelectorAll('.el-table__body .cell')[2]; // first row
triggerEvent(cell.parentNode.parentNode, 'dblclick');
expect(vm.result).to.length(2); // row, event
expect(vm.result).to.length(3); // row, event, column
expect(vm.result[0]).to.have.property('name').to.equal(getTestData()[0].name);
destroyVM(vm);
done();