Files
vxe-table/examples/views/table/advanced/MaxHeight.vue
xuliangzhan 0d3e5b33de 更新文档
2019-12-30 20:13:33 +08:00

241 lines
8.2 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-footer
show-overflow
max-height="400"
:loading="loading"
:data="tableData1"
:footer-method="footerMethod">
<vxe-table-column type="checkbox" width="60"></vxe-table-column>
<vxe-table-column type="seq" width="100"></vxe-table-column>
<vxe-table-column field="name" title="Name" sortable width="200"></vxe-table-column>
<vxe-table-column field="age" title="Age" width="120"></vxe-table-column>
<vxe-table-column field="rate" title="Rate" width="120"></vxe-table-column>
<vxe-table-column field="region" title="Region" width="200"></vxe-table-column>
<vxe-table-column field="address" title="Address" width="300" show-overflow></vxe-table-column>
<vxe-table-column field="updateTime" title="UpdateTime" width="200"></vxe-table-column>
<vxe-table-column field="createTime" title="CreateTime" width="200"></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>
<p class="tip">当数据超过最大高度时自动显示滚动条</p>
<vxe-table
border
resizable
show-footer
show-overflow
max-height="400"
:loading="loading"
:data="tableData2"
:footer-method="footerMethod">
<vxe-table-column type="checkbox" width="60"></vxe-table-column>
<vxe-table-column type="seq" width="100"></vxe-table-column>
<vxe-table-column field="name" title="Name" sortable width="200"></vxe-table-column>
<vxe-table-column field="age" title="Age" width="120"></vxe-table-column>
<vxe-table-column field="rate" title="Rate" width="120"></vxe-table-column>
<vxe-table-column field="time" title="Time" width="200"></vxe-table-column>
<vxe-table-column field="updateTime" title="UpdateTime" width="200"></vxe-table-column>
<vxe-table-column field="createTime" title="CreateTime" width="200"></vxe-table-column>
</vxe-table>
<p class="demo-code">{{ $t('app.body.button.showCode') }}</p>
<pre>
<code class="xml">{{ demoCodes[2] }}</code>
<code class="javascript">{{ demoCodes[3] }}</code>
</pre>
</div>
</template>
<script>
import XEUtils from 'xe-utils'
import hljs from 'highlight.js'
export default {
data () {
return {
loading: false,
tableData1: [],
tableData2: [],
demoCodes: [
`
<vxe-table
border
resizable
show-footer
show-overflow
max-height="400"
:loading="loading"
:data="tableData"
:footer-method="footerMethod">
<vxe-table-column type="checkbox" width="60"></vxe-table-column>
<vxe-table-column type="seq" width="100"></vxe-table-column>
<vxe-table-column field="name" title="Name" sortable width="200"></vxe-table-column>
<vxe-table-column field="age" title="Age" width="120"></vxe-table-column>
<vxe-table-column field="rate" title="Rate" width="120"></vxe-table-column>
<vxe-table-column field="region" title="Region" width="200"></vxe-table-column>
<vxe-table-column field="address" title="Address" width="300" show-overflow></vxe-table-column>
<vxe-table-column field="updateTime" title="UpdateTime" width="200"></vxe-table-column>
<vxe-table-column field="createTime" title="CreateTime" width="200"></vxe-table-column>
</vxe-table>
`,
`
export default {
data () {
return {
loading: false,
tableData: []
}
},
created () {
this.loading = true
setTimeout(() => {
this.tableData = window.MOCK_DATA_LIST.slice(0, 3)
this.loading = false
}, 300)
},
methods: {
footerMethod ({ columns, data }) {
const footerData = [
columns.map((column, columnIndex) => {
if (columnIndex === 0) {
return '平均'
}
if (['age', 'rate'].includes(column.property)) {
return XEUtils.mean(data, column.property).toFixed(2)
}
return null
}),
columns.map((column, columnIndex) => {
if (columnIndex === 0) {
return '和值'
}
if (['age', 'rate'].includes(column.property)) {
return XEUtils.sum(data, column.property)
}
return null
})
]
return footerData
}
}
}
`,
`
<vxe-table
border
resizable
show-footer
show-overflow
max-height="400"
:loading="loading"
:data="tableData"
:footer-method="footerMethod">
<vxe-table-column type="checkbox" width="60"></vxe-table-column>
<vxe-table-column type="seq" width="100"></vxe-table-column>
<vxe-table-column field="name" title="Name" sortable width="200"></vxe-table-column>
<vxe-table-column field="age" title="Age" width="120"></vxe-table-column>
<vxe-table-column field="rate" title="Rate" width="120"></vxe-table-column>
<vxe-table-column field="time" title="Time" width="200"></vxe-table-column>
<vxe-table-column field="updateTime" title="UpdateTime" width="200"></vxe-table-column>
<vxe-table-column field="createTime" title="CreateTime" width="200"></vxe-table-column>
</vxe-table>
`,
`
export default {
data () {
return {
loading: false,
tableData: []
}
},
created () {
this.loading = true
setTimeout(() => {
this.tableData = window.MOCK_DATA_LIST.slice(0, 50)
this.loading = false
}, 300)
},
methods: {
footerMethod ({ columns, data }) {
const footerData = [
columns.map((column, columnIndex) => {
if (columnIndex === 0) {
return '平均'
}
if (['age', 'rate'].includes(column.property)) {
return XEUtils.mean(data, column.property).toFixed(2)
}
return null
}),
columns.map((column, columnIndex) => {
if (columnIndex === 0) {
return '和值'
}
if (['age', 'rate'].includes(column.property)) {
return XEUtils.sum(data, column.property)
}
return null
})
]
return footerData
}
}
}
`
]
}
},
created () {
this.loading = true
setTimeout(() => {
this.tableData1 = window.MOCK_DATA_LIST.slice(0, 3)
this.tableData2 = window.MOCK_DATA_LIST.slice(0, 50)
this.loading = false
}, 300)
},
mounted () {
Array.from(this.$el.querySelectorAll('pre code')).forEach((block) => {
hljs.highlightBlock(block)
})
},
methods: {
footerMethod ({ columns, data }) {
const footerData = [
columns.map((column, columnIndex) => {
if (columnIndex === 0) {
return '平均'
}
if (['age', 'rate'].includes(column.property)) {
return XEUtils.mean(data, column.property).toFixed(2)
}
return null
}),
columns.map((column, columnIndex) => {
if (columnIndex === 0) {
return '和值'
}
if (['age', 'rate'].includes(column.property)) {
return XEUtils.sum(data, column.property)
}
return null
})
]
return footerData
}
}
}
</script>