Files
vxe-table/examples/views/table/scroll/ScrollRows.vue
xuliangzhan e942a01186 重构渲染
2023-09-02 12:16:03 +08:00

203 lines
8.0 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">
虚拟滚动渲染<br>
大数据不建议使用双向绑定的 <table-api-link name="data"/> 属性vue 监听会大数据会短暂的卡顿建议使用 <table-api-link prop="loadData"/>/<table-api-link prop="reloadData"/> 函数<br>
<table-api-link prop="data"/> <table-api-link prop="loadData"/>/<table-api-link prop="reloadData"/> 不应该同时使用请根据数据量决定使用哪种方式保证一致性<br>
<span class="red">启用纵向虚拟滚启动后不支持动态行高如果需要支持将虚拟滚动关闭即可</span>
</p>
<vxe-toolbar>
<template #buttons>
<vxe-button @click="loadList(5000)">5k条</vxe-button>
<vxe-button @click="loadList(10000)">1w条</vxe-button>
<vxe-button @click="loadList(50000)">5w条</vxe-button>
<vxe-button @click="loadList(100000)">10w条</vxe-button>
<vxe-button @click="loadList(200000)">20w条</vxe-button>
<vxe-button @click="loadList(300000)">30w条</vxe-button>
</template>
</vxe-toolbar>
<vxe-table
border
resizable
show-overflow
show-header-overflow
ref="xTable"
height="700"
:export-config="{}"
:sort-config="{trigger: 'cell'}"
:loading="loading"
:scroll-y="{enabled: true}">
<vxe-column type="seq" width="100"></vxe-column>
<vxe-column field="name" title="Name" sortable width="200"></vxe-column>
<vxe-column field="id" title="ID" 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="region" title="Region" width="200"></vxe-column>
<vxe-column field="time" title="Time" 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-column field="attr1" title="Attr1" width="200"></vxe-column>
<vxe-column field="attr2" title="Attr2" width="200"></vxe-column>
<vxe-column field="attr3" title="Attr3" width="200"></vxe-column>
<vxe-column field="attr4" title="Attr4" width="200"></vxe-column>
<vxe-column field="attr5" title="Attr5" width="200"></vxe-column>
<vxe-column field="attr6" title="Attr6" width="200"></vxe-column>
<vxe-column field="attr7" title="Attr7" width="200"></vxe-column>
<vxe-column field="attr8" title="Attr8" width="200"></vxe-column>
<vxe-column field="attr11" title="attr11" width="200"></vxe-column>
<vxe-column field="attr9" title="Attr9" width="200"></vxe-column>
<vxe-column field="attr10" title="attr10" 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>
</div>
</template>
<script>
export default {
data () {
return {
loading: false,
demoCodes: [
`
<vxe-toolbar export>
<template #buttons>
<vxe-button @click="loadList(5000)">5k条</vxe-button>
<vxe-button @click="loadList(10000)">1w条</vxe-button>
<vxe-button @click="loadList(50000)">5w条</vxe-button>
<vxe-button @click="loadList(100000)">10w条</vxe-button>
<vxe-button @click="loadList(200000)">20w条</vxe-button>
<vxe-button @click="loadList(300000)">30w条</vxe-button>
</template>
</vxe-toolbar>
<vxe-table
border
resizable
show-overflow
show-header-overflow
ref="xTable"
height="700"
:export-config="{}"
:sort-config="{trigger: 'cell'}"
:loading="loading">
<vxe-column type="seq" width="100"></vxe-column>
<vxe-column field="name" title="Name" sortable width="200"></vxe-column>
<vxe-column field="id" title="ID" 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="region" title="Region" width="200"></vxe-column>
<vxe-column field="time" title="Time" 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-column field="attr1" title="Attr1" width="200"></vxe-column>
<vxe-column field="attr2" title="Attr2" width="200"></vxe-column>
<vxe-column field="attr3" title="Attr3" width="200"></vxe-column>
<vxe-column field="attr4" title="Attr4" width="200"></vxe-column>
<vxe-column field="attr5" title="Attr5" width="200"></vxe-column>
<vxe-column field="attr6" title="Attr6" width="200"></vxe-column>
<vxe-column field="attr7" title="Attr7" width="200"></vxe-column>
<vxe-column field="attr8" title="Attr8" width="200"></vxe-column>
<vxe-column field="attr11" title="attr11" width="200"></vxe-column>
<vxe-column field="attr9" title="Attr9" width="200"></vxe-column>
<vxe-column field="attr10" title="attr10" width="200"></vxe-column>
</vxe-table>
`,
`
export default {
data () {
return {
loading: false
}
},
created () {
this.loadList(600)
},
methods: {
loadList (size) {
this.loading = true
this.mockList(size).then(data => {
// 使用函数式加载,阻断 vue 对大数据的监听
const xTable = this.$refs.xTable
const startTime = Date.now()
if (xTable) {
this.$refs.xTable.reloadData(data).then(() => {
this.$XModal.message({ content: \`渲染 \${size} 行,用时 \${Date.now() - startTime}毫秒\`, status: 'info' })
this.loading = false
})
}
})
},
mockList (size) {
return new Promise(resolve => {
const list = []
for (let index = 0; index < size; index++) {
list.push({
name: \`名称\${index}\`,
checked: false,
sex: '0',
num: 123,
age: 18,
num2: 234,
rate: 3,
address: 'shenzhen'
})
}
resolve(list)
})
}
}
}
`
]
}
},
created () {
this.loadList(600)
},
methods: {
loadList (size) {
this.loading = true
this.mockList(size).then(data => {
// 使用函数式加载,阻断 vue 对大数据的监听
const xTable = this.$refs.xTable
const startTime = Date.now()
if (xTable) {
this.$refs.xTable.reloadData(data).then(() => {
this.$XModal.message({ content: `渲染 ${size} 行,用时 ${Date.now() - startTime}毫秒`, status: 'info' })
this.loading = false
})
}
})
},
mockList (size) {
return new Promise(resolve => {
const list = []
for (let index = 0; index < size; index++) {
list.push({
name: `名称${index}`,
checked: false,
sex: '0',
num: 123,
age: 18,
num2: 234,
rate: 3,
address: 'shenzhen'
})
}
resolve(list)
})
}
}
}
</script>