mirror of
https://gitee.com/xuliangzhan_admin/vxe-table.git
synced 2026-01-21 05:27:57 +08:00
108 lines
3.3 KiB
Vue
108 lines
3.3 KiB
Vue
<template>
|
||
<div>
|
||
<p class="tip">使用 <table-api-link prop="highlight-current-row"/> 显示高亮行,当前行是唯一的;用户操作点击选项时会触发事件 <table-api-link prop="current-change"/></p>
|
||
|
||
<vxe-toolbar>
|
||
<template v-slot:buttons>
|
||
<vxe-button @click="$refs.xTable.setCurrentRow(tableData[1])">设置第二行选中</vxe-button>
|
||
<vxe-button @click="$refs.xTable.clearCurrentRow()">取消选中</vxe-button>
|
||
<vxe-button @click="getCurrentEvent">获取高亮行</vxe-button>
|
||
</template>
|
||
</vxe-toolbar>
|
||
|
||
<vxe-table
|
||
border
|
||
highlight-hover-row
|
||
highlight-current-row
|
||
ref="xTable"
|
||
height="300"
|
||
:data="tableData"
|
||
@current-change="currentChangeEvent">
|
||
<vxe-table-column field="name" title="Name"></vxe-table-column>
|
||
<vxe-table-column field="sex" title="Sex"></vxe-table-column>
|
||
<vxe-table-column field="age" title="Age"></vxe-table-column>
|
||
<vxe-table-column field="address" title="Address" show-overflow></vxe-table-column>
|
||
</vxe-table>
|
||
|
||
<p class="demo-code">{{ $t('app.body.button.showCode') }}</p>
|
||
|
||
<pre>
|
||
<code class="xml">{{ demoCodes[0] }}</code>
|
||
<code class="javascript">{{ demoCodes[1] }}</code>
|
||
</pre>
|
||
</div>
|
||
</template>
|
||
|
||
<script>
|
||
import hljs from 'highlight.js'
|
||
|
||
export default {
|
||
data () {
|
||
return {
|
||
tableData: [],
|
||
demoCodes: [
|
||
`
|
||
<vxe-toolbar>
|
||
<template v-slot:buttons>
|
||
<vxe-button @click="$refs.xTable.setCurrentRow(tableData[1])">设置第二行选中</vxe-button>
|
||
<vxe-button @click="$refs.xTable.clearCurrentRow()">取消选中</vxe-button>
|
||
<vxe-button @click="getCurrentEvent">获取高亮行</vxe-button>
|
||
</template>
|
||
</vxe-toolbar>
|
||
|
||
<vxe-table
|
||
border
|
||
highlight-hover-row
|
||
highlight-current-row
|
||
ref="xTable"
|
||
height="300"
|
||
:data="tableData"
|
||
@current-change="currentChangeEvent">
|
||
<vxe-table-column field="name" title="Name"></vxe-table-column>
|
||
<vxe-table-column field="sex" title="Sex"></vxe-table-column>
|
||
<vxe-table-column field="age" title="Age"></vxe-table-column>
|
||
<vxe-table-column field="address" title="Address" show-overflow></vxe-table-column>
|
||
</vxe-table>
|
||
`,
|
||
`
|
||
export default {
|
||
data () {
|
||
return {
|
||
tableData: []
|
||
}
|
||
},
|
||
created () {
|
||
this.tableData = window.MOCK_DATA_LIST.slice(0, 6)
|
||
},
|
||
methods: {
|
||
currentChangeEvent ({ row }) {
|
||
console.log('行选中事件')
|
||
},
|
||
getCurrentEvent () {
|
||
this.$XModal.alert(JSON.stringify(this.$refs.xTable.getCurrentRecord()))
|
||
}
|
||
}
|
||
}
|
||
`
|
||
]
|
||
}
|
||
},
|
||
mounted () {
|
||
Array.from(this.$el.querySelectorAll('pre code')).forEach((block) => {
|
||
hljs.highlightBlock(block)
|
||
})
|
||
},
|
||
created () {
|
||
this.tableData = window.MOCK_DATA_LIST.slice(0, 6)
|
||
},
|
||
methods: {
|
||
currentChangeEvent ({ rowIndex }) {
|
||
console.log(`行选中事件 ${rowIndex}`)
|
||
},
|
||
getCurrentEvent () {
|
||
this.$XModal.alert(JSON.stringify(this.$refs.xTable.getCurrentRecord()))
|
||
}
|
||
}
|
||
}
|
||
</script>
|