vxe-table 列宽拖拽形式设置,自适应列宽,固定列宽
在运用 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>
https://gitee.com/x-extends/vxe-table