如何在Vue3的Vuestic UI数据表格中冻结前两列
Vuestic UI Data Table 冻结前两列实现方案
Vuestic UI的数据表格组件**支持冻结列(固定列)**功能,可通过配置列属性实现冻结前两列的需求,具体实现步骤如下:
配置列定义:在列数组中,为需要冻结的前两列添加
fixed: true属性,标记该列为固定列const columns = [ { title: '第一列标题', field: 'column1', fixed: true // 启用左侧固定 }, { title: '第二列标题', field: 'column2', fixed: true // 启用左侧固定 }, { title: '第三列标题', field: 'column3' }, // 其他列配置... ]绑定到表格组件:将配置好的列数组传入
<VaDataTable>组件的columns属性<template> <VaDataTable :columns="columns" :items="tableItems" style="width: 100%; overflow-x: auto;" /> </template> <script setup> import { ref } from 'vue' // 列配置 const columns = ref([ { title: 'ID', field: 'id', fixed: true }, { title: '姓名', field: 'name', fixed: true }, { title: '部门', field: 'department' }, { title: '入职日期', field: 'joinDate' }, { title: '薪资', field: 'salary' } ]) // 表格数据示例 const tableItems = ref([ { id: 1, name: '张三', department: '技术部', joinDate: '2022-01-01', salary: 8000 }, { id: 2, name: '李四', department: '市场部', joinDate: '2022-03-15', salary: 7500 }, // 更多数据... ]) </script>注意事项:
- Vuestic UI数据表格目前仅支持左侧固定列,冻结列会始终停留在表格左侧
- 需确保表格容器存在横向滚动条件(比如设置足够宽的列或给表格添加
overflow-x: auto样式),否则固定列效果无法直观体现
内容的提问来源于stack exchange,提问作者pedrovgp
相关产品推荐
相关产品推荐

