el-popover box appears click the input table table, click to select, retrieve the complete alphabet can select Enter

<template>
<card>
<El-popover
placement="right"
width="400"
trigger="click"
>
<el-table
ref="singleTable"
:data="pinyinOptions"
highlight-current-row
style="width: 100%"
@current-change="handleCurrentChange"
>
<el-table-column
type="index"
width="50"
/>
<el-table-column
property="date"
label = "date"
width="120"
/>
<el-table-column
property="name"
label = "Name"
width="120"
/>
<el-table-column
property="address"
label = "Address"
/>
</el-table>
<!-- <div style="margin-top: 20px">
<El-button @ click = "setCurrent (tableData [1])"> second row select </ el-button>
<el-button @click="setCurrent()">取消选择</el-button>
</div> -->
<el-input
slot="reference"
v-model="input"
style="width:400px"
@input="PinyinMatch"
@keyup.enter.native="sel"
/>
</el-popover>

</card>
</template>

<script>
export default {
data() {
return {
tableData: [{
date: '2016-05-02',
name: 'John Doe',
address: 'Shanghai'
}, {
date: '2016-05-04',
name: 'Zhao Xiaohu',
address: 'Shijiazhuang'
}, {
date: '2016-05-01',
name: 'John Doe',
address: 'Baoding'
}, {
date: '2016-05-03',
name: 'Zhao six'
address: 'Tangshan'
}],
currentRow: null,
input: '',
pinyinOptions: []
}
},
created() {
this.pinyinOptions = this.tableData
},
methods: {
setCurrent(row) {
this.$refs.singleTable.setCurrentRow(row)
},
handleCurrentChange(val) {
this.currentRow = val
if (val !== undefined) {
this.input = val.name
} else {
this.input = ''
}
},
PinyinMatch(val) {
const PinyinEngine = require('pinyin-engine')
// Create Data Index
const pinyinEngine = new PinyinEngine(this.tableData, ['name'])
// Inquire
const pinyinVal = pinyinEngine.query(val)
this.pinyinOptions = pinyinVal
},
cell () {
this.input = this.pinyinOptions[0].name
}
}
}
</script>

Guess you like

Origin www.cnblogs.com/hellofangfang/p/10972721.html