Files
vxe-table/examples/views/table/scroll/MaxHeight.vue
xuliangzhan 9313472d3c update docs
2021-10-24 21:31:02 +08:00

241 lines
7.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div>
<p class="tip">最大高度通过设置 <table-api-link prop="max-height"/> 启用当数据少时自适应</p>
<vxe-table
border
resizable
show-overflow
ref="xTable1"
max-height="400"
:loading="loading">
<vxe-column type="checkbox" width="60"></vxe-column>
<vxe-column type="seq" width="100"></vxe-column>
<vxe-column field="name" title="Name" sortable width="200"></vxe-column>
<vxe-column field="age" title="Age" width="200"></vxe-column>
<vxe-column field="sex" title="Sex" width="200"></vxe-column>
<vxe-column field="region" title="Region" width="200"></vxe-column>
<vxe-column field="address" title="Address" width="300" show-overflow></vxe-column>
<vxe-column field="updateTime" title="UpdateTime" width="200"></vxe-column>
<vxe-column field="createTime" title="CreateTime" width="200"></vxe-column>
</vxe-table>
<p class="demo-code">{{ $t('app.body.button.showCode') }}</p>
<pre>
<pre-code class="xml">{{ demoCodes[0] }}</pre-code>
<pre-code class="javascript">{{ demoCodes[1] }}</pre-code>
</pre>
<p class="tip">当数据超过最大高度时自动显示滚动条</p>
<vxe-table
border
resizable
show-overflow
ref="xTable2"
max-height="400"
:loading="loading">
<vxe-column type="checkbox" width="60"></vxe-column>
<vxe-column type="seq" width="100"></vxe-column>
<vxe-column field="name" title="Name" sortable width="200"></vxe-column>
<vxe-column field="age" title="Age" width="200"></vxe-column>
<vxe-column field="rate" title="Rate" width="200"></vxe-column>
<vxe-column field="time" title="Time" width="200"></vxe-column>
<vxe-column field="updateTime" title="UpdateTime" width="200"></vxe-column>
<vxe-column field="createTime" title="CreateTime" width="200"></vxe-column>
</vxe-table>
<p class="demo-code">{{ $t('app.body.button.showCode') }}</p>
<pre>
<pre-code class="xml">{{ demoCodes[2] }}</pre-code>
<pre-code class="javascript">{{ demoCodes[3] }}</pre-code>
</pre>
</div>
</template>
<script>
export default {
data () {
return {
loading: false,
demoCodes: [
`
<vxe-table
border
resizable
show-overflow
ref="xTable"
max-height="400"
:loading="loading">
<vxe-column type="checkbox" width="60"></vxe-column>
<vxe-column type="seq" width="100"></vxe-column>
<vxe-column field="name" title="Name" sortable width="200"></vxe-column>
<vxe-column field="age" title="Age" width="200"></vxe-column>
<vxe-column field="region" title="Region" width="200"></vxe-column>
<vxe-column field="address" title="Address" width="300" show-overflow></vxe-column>
<vxe-column field="updateTime" title="UpdateTime" width="200"></vxe-column>
<vxe-column field="createTime" title="CreateTime" width="200"></vxe-column>
</vxe-table>
`,
`
export default {
data () {
return {
loading: false
}
},
created () {
this.findList()
},
methods: {
findList () {
this.loading = true
return new Promise(resolve => {
setTimeout(() => {
let tableData = this.mockList(3)
// 阻断 vue 对大数组的监听,避免 vue 绑定大数据造成短暂的卡顿
if (this.$refs.xTable) {
this.$refs.xTable.loadData(tableData)
}
resolve()
this.loading = false
}, 300)
})
},
mockList (size) {
const list = []
for (let index = 0; index < size; index++) {
list.push({
name: \`名称\${index}\`,
sex: '0',
num: 123,
age: 18,
num2: 234,
rate: 3,
address: 'shenzhen'
})
}
return list
}
}
}
`,
`
<vxe-table
border
resizable
show-overflow
ref="xTable"
max-height="400"
:loading="loading">
<vxe-column type="checkbox" width="60"></vxe-column>
<vxe-column type="seq" width="100"></vxe-column>
<vxe-column field="name" title="Name" sortable width="200"></vxe-column>
<vxe-column field="age" title="Age" width="200"></vxe-column>
<vxe-column field="sex" title="Sex" width="200"></vxe-column>
<vxe-column field="rate" title="Rate" width="200"></vxe-column>
<vxe-column field="time" title="Time" width="200"></vxe-column>
<vxe-column field="updateTime" title="UpdateTime" width="200"></vxe-column>
<vxe-column field="createTime" title="CreateTime" width="200"></vxe-column>
</vxe-table>
`,
`
export default {
data () {
return {
loading: false
}
},
created () {
this.findList()
},
methods: {
findList () {
this.loading = true
return new Promise(resolve => {
setTimeout(() => {
let tableData = this.mockList(60)
// 阻断 vue 对大数组的监听,避免 vue 绑定大数据造成短暂的卡顿
if (this.$refs.xTable) {
this.$refs.xTable.loadData(tableData)
}
resolve()
this.loading = false
}, 300)
})
},
mockList (size) {
const list = []
for (let index = 0; index < size; index++) {
list.push({
name: \`名称\${index}\`,
sex: '0',
num: 123,
age: 18,
num2: 234,
rate: 3,
address: 'shenzhen'
})
}
return list
}
}
}
`
]
}
},
created () {
this.findList1()
this.findList2()
},
methods: {
findList1 () {
this.loading = true
return new Promise(resolve => {
setTimeout(() => {
const tableData = this.mockList(3)
// 阻断 vue 对大数组的监听,避免 vue 绑定大数据造成短暂的卡顿
if (this.$refs.xTable1) {
this.$refs.xTable1.loadData(tableData)
}
resolve()
this.loading = false
}, 300)
})
},
findList2 () {
this.loading = true
return new Promise(resolve => {
setTimeout(() => {
const tableData = this.mockList(60)
// 阻断 vue 对大数组的监听,避免 vue 绑定大数据造成短暂的卡顿
if (this.$refs.xTable2) {
this.$refs.xTable2.loadData(tableData)
}
resolve()
this.loading = false
}, 300)
})
},
mockList (size) {
const list = []
for (let index = 0; index < size; index++) {
list.push({
name: `名称${index}`,
sex: '0',
num: 123,
age: 18,
num2: 234,
rate: 3,
address: 'shenzhen'
})
}
return list
}
}
}
</script>