Files
vxe-table/examples/views/table/grid/Basic.vue
xuliangzhan bae5665d50 update
2019-05-11 16:19:25 +08:00

242 lines
5.5 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>使用 vxe-grid 配置的方式渲染表格这对一些动态渲染的场景非常有用完全使用数据进行配置</p>
<vxe-grid
border
height="300"
:columns="tableColumn"
:data.sync="tableData"></vxe-grid>
<p>调用代码</p>
<pre>
<code class="xml">{{ demoCodes[0] }}</code>
<code class="javascript">{{ demoCodes[1] }}</code>
</pre>
<p>分组表头底部合计</p>
<vxe-grid
border
stripe
show-footer
height="500"
:footer-method="footerMethod"
:columns="tableColumn2"
:data.sync="tableData"></vxe-grid>
<p>调用代码</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 {
tableColumn: [
{
type: 'index',
width: 60
},
{
prop: 'name',
label: 'Name'
},
{
prop: 'sex',
label: 'Sex'
},
{
prop: 'address',
label: 'Address',
showOverflowTooltip: true
}
],
tableColumn2: [
{
type: 'index',
width: 60
},
{
label: '基本信息',
children: [
{
prop: 'name',
label: 'Name'
},
{
label: '其他信息',
children: [
{
prop: 'rate',
label: 'Rate'
},
{
prop: 'age',
label: 'Age'
}
]
},
{
prop: 'sex',
label: 'Sex'
}
]
},
{
prop: 'address',
label: 'Address',
showOverflowTooltip: true
}
],
tableData: [],
demoCodes: [
`
<vxe-grid
border
height="300"
:columns="tableColumn"
:data.sync="tableData"></vxe-grid>
`,
`
export default {
data () {
return {
tableColumn: [
{
type: 'index',
width: 60
},
{
prop: 'name',
label: 'Name'
},
{
prop: 'sex',
label: 'Sex'
},
{
prop: 'address',
label: 'Address',
showOverflowTooltip: true
}
]
}
},
created () {
this.tableData = window.MOCK_DATA_LIST.slice(0, 100)
}
}
`,
`
<vxe-grid
border
stripe
show-footer
height="500"
:footer-method="footerMethod"
:columns="tableColumn2"
:data.sync="tableData"></vxe-grid>
`,
`
export default {
data () {
return {
tableColumn: [
{
type: 'index',
width: 60
},
{
label: '基本信息',
children: [
{
prop: 'name',
label: 'Name'
},
{
label: '其他信息',
children: [
{
prop: 'rate',
label: 'Rate'
},
{
prop: 'age',
label: 'Age'
}
]
},
{
prop: 'sex',
label: 'Sex'
}
]
},
{
prop: 'address',
label: 'Address',
showOverflowTooltip: true
}
]
}
},
created () {
this.tableData = window.MOCK_DATA_LIST.slice(0, 100)
},
methods: {
footerMethod ({ columns, data }) {
return [
columns.map((column, columnIndex) => {
if (columnIndex === 0) {
return '和值'
}
if (['age', 'rate'].includes(column.property)) {
return XEUtils.sum(data, column.property)
}
return '-'
})
]
}
}
}
`
]
}
},
created () {
let list = window.MOCK_DATA_LIST.slice(0, 100)
this.tableData = list
},
mounted () {
this.$el.querySelectorAll('pre code').forEach((block) => {
hljs.highlightBlock(block)
})
},
methods: {
footerMethod ({ columns, data }) {
return [
columns.map((column, columnIndex) => {
if (columnIndex === 0) {
return '和值'
}
if (['age', 'rate'].includes(column.property)) {
return XEUtils.sum(data, column.property)
}
return '-'
})
]
}
}
}
</script>