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

uniapp实现表格冻结

 效果图如下:

思路:

1.由于APP项目需要,起初想去插件市场直接找现成的,结果找了很久没找到合适的(有的不支持vue2有的不能都支持APP和小程序)

2.后来,就只能去改uni-table源码了,因为u-table不支持固定列。

直接上代码

注意:需要动态计算表头高度

<template><view class="content"><uni-table ref="table" :loading="loading" border stripe emptyText="暂无更多数据"><view class="table-header"><uni-tr><uni-th width="120" align="center" class="sticky-column">名称</uni-th><uni-th width="100" align="center">标签名</uni-th><uni-th width="100" align="center">CNB-槽号-通道</uni-th><uni-th width="100" align="center">量程</uni-th><uni-th width="100" align="center">预警值</uni-th><uni-th width="100" align="center">联锁值</uni-th><uni-th width="100" align="center">程序停机点名</uni-th><uni-th width="180" align="center">操作</uni-th></uni-tr></view><view class="warper" :style="{ maxHeight: 'calc(100vh - ' + boxHeight + 'rpx)' }"><uni-tr v-for="(item, index) in tableData" :key="index"><uni-td width="120">{{item.name }}</uni-td><uni-td width="100"><view><u-tag :text="item.tagname" size="mini" type="primary"></u-tag></view></uni-td><uni-td width="100"><view class="name">{{ item.passage }}</view></uni-td><uni-td width="100"><view>{{ item.range }}</view></uni-td><uni-td width="100">{{ item.prewarningValue }}</uni-td><uni-td width="100">{{ item.interlockingValue }}</uni-td><uni-td width="100"><u-tag :text="item.programStop" size="mini" type="warning"></u-tag></uni-td><uni-td><view class="uni-group"><u-button class="uni-button" size="mini" type="primary"@click="selectdetail(index,item)">查看</u-button></view></uni-td></uni-tr></view></uni-table></view>
</template><script>import tableList from '@/subRemoteOperate/untilMethods/table/tableList.js';export default {data() {return {loading: false,boxHeight: 0, // box盒子的高度tableData: tableList.data}},mounted() {this.getBoxHeight();},methods: {//获取盒子高度getBoxHeight() {uni.createSelectorQuery().in(this).select('.table-header').boundingClientRect(rect => {if (rect) {this.boxHeight = rect.height;}}).exec();},}}
</script><style lang="scss" scoped>.content {width: 100%;height: 100vh;}.table-header {position: sticky;left: 0;top: 0;z-index: 99999;background-color: #fff;}//冻结表头第一列/deep/ .uni-table-tr .uni-table-td:first-child {position: sticky;left: 0;top: 0;background-color: #fff;z-index: 9999;}/deep/ .uni-table-tr {overflow: visible;background-color: #fff;}/deep/ .uni-table-tr .uni-table-th:first-child {position: sticky;left: 0;top: 0;background-color: #fff;z-index: 9999;}
</style>

http://www.lryc.cn/news/174481.html

相关文章:

  • Spring面试题11:什么是Spring的依赖注入
  • 用于设计 CNN 的 7 种不同卷积
  • 备受以太坊基金会青睐的 Hexlink,构建亿级用户涌入 Web3的入口
  • 合约升级标准 ERC2535 的设计解析和不足
  • 【Vue】ElementUI实现登录注册
  • linux 安装 wordpress
  • LeetCode902最大为 N 的数字组合(相关话题:数位DP问题,递归遍历和减枝)
  • USB总线-Linux内核USB3.0主机控制器驱动框架分析(十二)
  • SQL模板-用户留存率计算
  • LeakCanary 源码详解(3)
  • springboot使用SSE
  • 搞定ESD(一):静电放电测试标准解析
  • 问界M7的诸多优点(自动驾驶走进我们的生活二)
  • [运维|数据库] msql中的 FIND_IN_SET如何转化为pg数据中的ARRAY_POSITION的函数
  • LeetCode 面试题 05.03. 翻转数位
  • Fiddler抓包工具配置+Jmeter基本使用
  • IOTE 2023国际物联网展直击:芯与物发布全新定位芯片,助力多领域智能化发展
  • 【软件设计师-从小白到大牛】上午题基础篇:第二章 操作系统
  • 【20230921】关于sing-box命令行程序开机自启动运行(Windows、Linux)
  • LeetCode 75-02:字符串的最大公因子
  • k8s1.19使用ceph14
  • Leetcode 50. Pow(x, n)
  • hive分区表的元数据信息numRows显示为0
  • Baumer工业相机堡盟工业相机如何通过BGAPI SDK设置相机的图像剪切(ROI)功能(C++)
  • 【云原生】聊聊为什么需要docker以及其基础架构
  • “高级前端开发技术探索路由的使用及Node安装使用“
  • LeetCode 494.目标和 (动态规划 + 性能优化)二维数组 压缩成 一维数组
  • [36c3 2019]includer
  • Python150题day10
  • Autosar工具-Davinci Developer