在使用 vxe-table 是,常用的列寬拖拽調整功能,透過列寬調整可以讓使用者靈活的自定義列寬。兩種拖拽調整列寬模式分別用於不同場景。
動態列寬分配模式
調整列寬之後,對於未設定列寬的列會重新動態分配剩餘寬度
<template>
<div>
<vxe-grid v-bind="gridOptions"></vxe-grid>
</div>
</template>
<script>
export default {
data () {
const gridOptions = {
border: true,
columnConfig: {
resizable: true
},
columns: [
{ type: 'seq', width: 70 },
{ field: 'name', title: 'Name' },
{ field: 'sex', title: '最小列寬', minWidth: '20%' },
{ field: 'age', title: 'Age' },
{ field: 'time', title: 'Time' },
{ field: 'address', title: 'Address' }
],
data: [
{ id: 10001, name: 'Test1', role: 'Develop', sex: 'Man', age: 28, address: 'test abc' },
{ id: 10002, name: 'Test2', role: 'Test', sex: 'Women', age: 22, address: 'Guangzhou' },
{ id: 10003, name: 'Test3', role: 'PM', sex: 'Man', age: 32, address: 'Shanghai' },
{ id: 10004, name: 'Test4', role: 'Designer', sex: 'Women', age: 24, address: 'Shanghai' }
]
}
return {
gridOptions
}
}
}
</script>
列寬固定拖拽模式
透過設定 resizable-config.dragMode='fixed' 屬性啟用固定寬度模式;
在該模式下拖拽列寬之後將會始終保持和介面看到的列寬完全一致,不會再重新動態分配剩餘列寬
<template>
<div>
<vxe-grid v-bind="gridOptions"></vxe-grid>
</div>
</template>
<script>
export default {
data () {
const gridOptions = {
border: true,
columnConfig: {
resizable: true
},
resizableConfig: {
dragMode: 'fixed'
},
columns: [
{ type: 'seq', width: 70 },
{ field: 'name', title: 'Name' },
{ field: 'sex', title: '最小列寬', minWidth: '20%' },
{ field: 'age', title: 'Age' },
{ field: 'time', title: 'Time' },
{ field: 'address', title: 'Address' }
],
data: [
{ id: 10001, name: 'Test1', role: 'Develop', sex: 'Man', age: 28, address: 'test abc' },
{ id: 10002, name: 'Test2', role: 'Test', sex: 'Women', age: 22, address: 'Guangzhou' },
{ id: 10003, name: 'Test3', role: 'PM', sex: 'Man', age: 32, address: 'Shanghai' },
{ id: 10004, name: 'Test4', role: 'Designer', sex: 'Women', age: 24, address: 'Shanghai' }
]
}
return {
gridOptions
}
}
}
</script>