Files
vxe-table/examples/views/table/advanced/CustomlWidthStorage.vue
xuliangzhan 94c1a651b3 更新文档
2019-12-15 18:02:26 +08:00

107 lines
3.1 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">
显示/隐藏列和列宽拖动保存功能通过设置 <toolbar-api-link prop="id"/> <toolbar-api-link prop="resizable"/>={storage: true} 参数开启列宽拖动 localStorage 保存功能<br>
还可以通过 <toolbar-api-link prop="checkMethod"/> 设置个性化列禁止勾选<br>
也可以通过配合 <table-api-link prop="resizable-change"/> 事件实现服务端保存
</p>
<vxe-toolbar id="toolbar_demo5" :resizable="{storage: true}" :custom="{storage: true, checkMethod: checkColumnMethod}">
<template v-slot:buttons>
<vxe-button>按钮1</vxe-button>
<vxe-button>按钮2</vxe-button>
</template>
</vxe-toolbar>
<vxe-table
border
resizable
height="400"
:data="tableData">
<vxe-table-column type="seq" width="60"></vxe-table-column>
<vxe-table-column field="name" title="Name"></vxe-table-column>
<vxe-table-column field="role" title="Role"></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>
<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 id="toolbar_demo5" :resizable="{storage: true}" :custom="{storage: true, checkMethod: checkColumnMethod}">
<template v-slot:buttons>
<vxe-button>按钮1</vxe-button>
<vxe-button>按钮2</vxe-button>
</template>
</vxe-toolbar>
<vxe-table
border
resizable
height="400"
:data="tableData">
<vxe-table-column type="seq" width="60"></vxe-table-column>
<vxe-table-column field="name" title="Name"></vxe-table-column>
<vxe-table-column field="role" title="Role"></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>
`,
`
export default {
data () {
return {
tableData: []
}
},
created () {
this.tableData = window.MOCK_DATA_LIST.slice(0, 20)
},
methods: {
checkColumnMethod ({ column }) {
if (column.property === 'role') {
return false
}
return true
}
}
}
`
]
}
},
created () {
let list = window.MOCK_DATA_LIST.slice(0, 20)
this.tableData = list
},
mounted () {
Array.from(this.$el.querySelectorAll('pre code')).forEach((block) => {
hljs.highlightBlock(block)
})
},
methods: {
checkColumnMethod ({ column }) {
if (column.property === 'role') {
return false
}
return true
}
}
}
</script>