当前位置: 首页 > news >正文

and design vue表格列宽度拖拽,vue-draggable-resizable插件使用

and design vue2版的table表格不能拖拽列的宽度,通过vue-draggable-resizable插件实现
我用的是and design 1.7.8的版本,先下插件

yarn add vue-draggable-resizable@2.1.0

我这版本的and design用最新3.0.0以上的插件会有问题,实现不了效果,换了低版本就没问题了
官方也有教使用方法,但会报错,按照官方的来写,需要把ResizeableTitle改成resizeableTitle这样就解决了最开始的报错
在这里插入图片描述
官方使用地址
下面是我封装的table公用组件,但是这样弄问题很多,在表格里加一下操作的时候很容易有问题,所以谨慎用这玩意

<template><div class="tableCommon-wrapper"><a-tablev-if="istrue":expandIconColumnIndex="expandIconColumnIndex" :expandIconAsCell="expandIconAsCell":defaultExpandAllRows="defaultExpandAllRows" :columns="columns" :dataSource="data" :loading="loading":indentSize="indentSize" :pagination="pagination" :row-selection="rowSelection":childrenColumnName="childrenColumnName" size="middle" :customHeaderRow="tableHeader" @change="handleTableChange":rowKey="rowkey" :scroll="scroll" :bordered="bordered" :hideDefaultSelections="hideDefaultSelections":components="components"><template slot-scope="text, record, index" :slot="slot"v-for="slot in Object.keys($scopedSlots).filter(key => key !== 'expandedRowRender')"><slot :name="slot" v-bind="{ text, record, index }"></slot></template></a-table></div>
</template><script>
import Vue from "vue";
import VueDraggableResizable from "vue-draggable-resizable";
Vue.component("vue-draggable-resizable", VueDraggableResizable);export default {name: 'ttable',props: {childrenColumnName: {type: String},rowkey: {type: String},tableHead: {type: Array,required: true},tableData: {type: Array,required: true},loading: {type: Boolean,default: false},indentSize: {// eslint-disable-next-line vue/require-prop-type-constructortype: Boolean | Number},pagination: {// eslint-disable-next-line vue/require-prop-type-constructortype: Boolean | Object},rowSelection: {type: Object},scroll: {type: Object,// default:()=> ({x: 1200, y: 600}) ,},expandIconAsCell: {type: Boolean},expandIconColumnIndex: {type: Number},size: {// eslint-disable-next-line vue/require-prop-type-constructortype: String | Number},bordered: {type: Boolean,default: true},defaultExpandAllRows: {type: Boolean,default: false},hideDefaultSelections: {type: Boolean,default: false}},data() {return {data:[],columns:[],istrue:false,}},watch:{tableHead(newdata){console.log('表格头部',newdata)this.columns = JSON.parse(JSON.stringify(newdata));},tableData(newdata){console.log('表格数据',newdata)this.data = JSON.parse(JSON.stringify(newdata));}},mounted(){this.init()},methods: {init(){console.log('阿里嘎多',this.tableHead)const draggingMap = {};this.columns = JSON.parse(JSON.stringify(this.tableHead));// this.columns = columns;this.data = JSON.parse(JSON.stringify(this.tableData));this.columns.forEach(col => {draggingMap[col.key] = col.width;});const draggingState = Vue.observable(draggingMap);const that = this;this.components = {header: {cell: (h, props, children) => {let thDom = null;const { key, ...restProps } = props;const col = that.columns.find(col => {const k = col.dataIndex || col.key;return k === key;});if (!col.width) {return <th {...restProps}>{children}</th>;}const onDrag = (x, y) => {draggingState[key] = 0;col.width = Math.max(x, 1);};const onDragstop = () => {draggingState[key] = thDom.getBoundingClientRect().width;};return (<th{...restProps}v-ant-ref={r => (thDom = r)}width={col.width}class="resize-table-th">{children}<vue-draggable-resizablekey={col.key}class="table-draggable-handle"w={10}x={draggingState[key] || col.width}z={1}axis="x"draggable={true}resizable={false}onDragging={onDrag}onDragstop={onDragstop}/></th>);}}};this.istrue=true;console.log('来阿拉啦啦啦',this.components)},tableHeader(column) {// console.log("column",column);column.forEach((e, index) => {column[index].className = 'table-thead';});},handleTableChange(val) {console.log("valllsadlalsdlsa:",val);this.$emit('changeCurrent', val.current);}}
}
</script><style lang='scss'>
.resize-table-th {position: relative;.table-draggable-handle {height: 100% !important;bottom: 0;left: auto !important;right: -5px;cursor: col-resize;touch-action: none;}
}::v-deep .ant-table-thead>tr>th {background: #f6f6f6;height: 50px;font-family: PingFang SC-Medium, PingFang SC;
}::v-deep .ant-table-tbody {background-color: #ffffff;
}::v-deep .ant-table-header-column .ant-table-column-title {font-size: 15px;font-weight: bold;font-family: Microsoft YaHei-Bold, Microsoft YaHei;color: #333333;
}
</style>

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 软件工程(4)面向对象方法:面向对象软件工程OOSE与案例实践
  • 编程艺术的细枝末节:深入探索调用约定
  • 仿twitter社区源码推特PHP源码
  • xss靶场详解
  • Redis的数据结构——Hash表
  • 如何提升 RocketMQ 顺序消费性能?
  • 如何在Linux/Debian/Ubuntu上将WebP图片转换为PNG格式
  • PCIE过渡时间(Transition Time)To P2、From P2、TO/From Non P2三个参数
  • 【pyqt5】QLineEdit中的文本输入限制方式,输入校验规则的应用详解
  • 文心快码 Baidu Comate 前端工程师观点分享:以文心快码 Baidu Comate为例,智能代码助手需要什么(一)
  • 《重生到现代之从零开始的C语言生活》—— 指针3
  • 手机运动信息管理系统
  • Oracle(76)如何收集统计信息?
  • 深度解析Python PyInstaller打包EXE的详细教程
  • C#发送邮件功能实现全面指南?有哪些方法?
  • [译]如何构建服务器端web组件,为何要构建?
  • 【刷算法】从上往下打印二叉树
  • 08.Android之View事件问题
  • CSS居中完全指南——构建CSS居中决策树
  • Druid 在有赞的实践
  • JAVA并发编程--1.基础概念
  • js
  • Vue 2.3、2.4 知识点小结
  • vue-router的history模式发布配置
  • 腾讯优测优分享 | Android碎片化问题小结——关于闪光灯的那些事儿
  • 赢得Docker挑战最佳实践
  • 最近的计划
  • ​Spring Boot 分片上传文件
  • ​用户画像从0到100的构建思路
  • # Redis 入门到精通(一)数据类型(4)
  • # 服务治理中间件详解:Spring Cloud与Dubbo
  • #Z2294. 打印树的直径
  • (1综述)从零开始的嵌入式图像图像处理(PI+QT+OpenCV)实战演练
  • (C#)if (this == null)?你在逗我,this 怎么可能为 null!用 IL 编译和反编译看穿一切
  • (C#)Windows Shell 外壳编程系列4 - 上下文菜单(iContextMenu)(二)嵌入菜单和执行命令...
  • (Matlab)使用竞争神经网络实现数据聚类
  • (PySpark)RDD实验实战——取最大数出现的次数
  • (二十一)devops持续集成开发——使用jenkins的Docker Pipeline插件完成docker项目的pipeline流水线发布
  • (三)centos7案例实战—vmware虚拟机硬盘挂载与卸载
  • (三)模仿学习-Action数据的模仿
  • (十六)视图变换 正交投影 透视投影
  • (一)utf8mb4_general_ci 和 utf8mb4_unicode_ci 适用排序和比较规则场景
  • (源码版)2024美国大学生数学建模E题财产保险的可持续模型详解思路+具体代码季节性时序预测SARIMA天气预测建模
  • .net Application的目录
  • .NET CORE使用Redis分布式锁续命(续期)问题
  • .NET8使用VS2022打包Docker镜像
  • .netcore 如何获取系统中所有session_ASP.NET Core如何解决分布式Session一致性问题
  • .Net程序猿乐Android发展---(10)框架布局FrameLayout
  • /var/spool/postfix/maildrop 下有大量文件
  • @Conditional注解详解
  • @serverendpoint注解_SpringBoot 使用WebSocket打造在线聊天室(基于注解)
  • [ 数据结构 - C++]红黑树RBTree
  • [ 隧道技术 ] cpolar 工具详解之将内网端口映射到公网
  • [23] 4K4D: Real-Time 4D View Synthesis at 4K Resolution
  • [C#]使用DlibDotNet人脸检测人脸68特征点识别人脸5特征点识别人脸对齐人脸比对FaceMesh