码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • a-table 动态列宽拖拽 vue


    所需依赖及版本:

    "vue-draggable-resizable": "^2.3.0"

    "ant-design-vue": "1.7.8"

    封装dragMixin文件:

    1. import VueDraggableResizable from 'vue-draggable-resizable';
    2. import '@/assets/less/draggableResizable.less'
    3. export const draggableResizable = {
    4. components: {
    5. VueDraggableResizable
    6. },
    7. data() {
    8. return {}
    9. },
    10. created() {
    11. },
    12. mounted() {
    13. let nodeTable = document.getElementsByClassName('ant-table-fixed')
    14. nodeTable[0].style.removeProperty("width")
    15. },
    16. methods: {
    17. /**
    18. * 表格列可拖拽
    19. * 表格上使用::components="drag(columns)"
    20. * tips:columns中需包含dataIndex或者key和width(Number)
    21. */
    22. drag(columns) {
    23. return {
    24. header: {
    25. cell: this.initDrag(columns),
    26. },
    27. }
    28. },
    29. initDrag(columns) {
    30. return (h, props, children) => {
    31. const {key, ...restProps} = props
    32. const col = columns.find((col) => {
    33. const k = col.dataIndex || col.key
    34. return k === key
    35. })
    36. if (!col || !col.width) {
    37. return h('th', {...restProps}, [...children])
    38. }
    39. const dragProps = {
    40. key: col.dataIndex || col.key,
    41. class: 'table-draggable-handle',
    42. attrs: {
    43. w: 10,
    44. x: col.width,
    45. z: 1,
    46. axis: 'x',
    47. draggable: true,
    48. resizable: false,
    49. },
    50. on: {
    51. dragging: (x, y) => {
    52. col.width = Math.max(x, 1)
    53. },
    54. },
    55. }
    56. const drag = h('vue-draggable-resizable', {...dragProps})
    57. return h('th', {...restProps, class: 'resize-table-th'}, [...children, drag])
    58. }
    59. }
    60. }
    61. }

    dragResizable.less 文件:

    1. .resize-table-th {
    2. position: relative;
    3. .table-draggable-handle {
    4. transform: none !important;
    5. position: absolute;
    6. height: 100% !important;
    7. bottom: 0;
    8. left: auto !important;
    9. right: 0;
    10. cursor: col-resize;
    11. touch-action: none;
    12. }
    13. }
    14. .ant-table-header-column > div {
    15. overflow: hidden;
    16. white-space: nowrap;
    17. text-overflow: ellipsis;
    18. }

    组件内使用:

    1. :components="drag(columns)" 利用a-table components api自定义table
    2. <a-table
    3. ref="table"
    4. size="middle"
    5. :scroll="{ x: true }"
    6. bordered
    7. rowKey="id"
    8. :components="drag(columns)"
    9. :columns="columns"
    10. :dataSource="dataSource"
    11. :pagination="ipagination"
    12. :loading="loading"
    13. :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
    14. class="j-table-force-nowrap"
    15. @change="handleTableChange"
    16. >
    17. </a-table>

  • 相关阅读:
    2024真正有效的苹果mac电脑清理工具CleanMyMac X
    AI全栈大模型工程师(六)进阶技巧
    二叉排序树的查找(递归、非递归)
    闭包:什么是闭包、闭包的作用、闭包的解决
    RCD负载箱的安全性能和认证标准有哪些?
    [附源码]Python计算机毕业设计SSM家纺商品展示平台(程序+LW)
    计算机毕业设计(附源码)python在线学习交流平台
    360°全景等功能关闭只是开始?汽车数据安全战争即将爆发
    使用 Spring Boot 设置 Hibernate Envers
    TikTok:年轻一代的创新驱动力与社会影响
  • 原文地址:https://blog.csdn.net/qq_40963664/article/details/133846841
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号