uni-app解决表格uni-table样式问题

一、如何让表格文字只显示一行,超出部分用省略号表示

步骤 :
  • 给table设置table-layout:fixed; 列宽由表格宽度和列宽度设定。(默认是由单元格内容设定)
  • 让表格元素继承父元素宽度固定table-layout: inherit;
  • overflow: hidden;超过部分隐藏,text-overflow: ellipsis; 超出部分用省略号表示 ,white-space: nowrap; 不换行。
  • 给表格设置宽度:width: 360rpx; box-sizing: content-box;(计算过程不包括边框)
代码:
html 复制代码
  .uni-table {
    table-layout: fixed;
    // height: 15.5rem;
    overflow: hidden;
    text-overflow: ellipsis; //省略号表示
    white-space: nowrap; //不换行

    .uni-table-td {
      table-layout: inherit;
      overflow: hidden;
      text-overflow: ellipsis; //省略号表示
      white-space: nowrap; //不换行
    }

    .uni-table-th {
      width: 360rpx; // !important
      box-sizing: content-box;
    }
  }

二、如何固定表的第一列

步骤:

在第一列uni-th中加上类名first,随后设置固定位置,个人尝试过使用position: sticky;在App中并没有生效。此外,element-plus导入到uni-app项目运行到真机中也会报错,因为样式冲突和导入方式等问题,无法使用,后续找到解决方案会更新,所以没有使用el-table来实现。

代码:
html 复制代码
.first {
	width: 120rpx;
	position: fixed;
	background-color: #FFFAF2;
	z-index: 10;
}

三、如何利用弹出层实现弹框效果

步骤:
代码:
html 复制代码
<!-- 弹出层 -->
<uni-popup ref="popup" :mask-click="false">
	<uni-table ref="table" border stripe>
		<uni-tr>
			<uni-th width="90" align="center">123</uni-th>
			<uni-th width="200" align="center">123</uni-th>

		</uni-tr>
		<uni-tr>
			<uni-th width="90" align="center">234</uni-th>
			<uni-th width="200" align="center">234</uni-th>

		</uni-tr>
		<uni-tr>
			<uni-th width="90" align="center">345</uni-th>
			<uni-th width="200" align="center">345</uni-th>
		</uni-tr>

	</uni-table>
	<button @click="close">关闭</button>
</uni-popup>

四、总数据条数和分页索引如何显示

步骤:

通过检查页面效果来找到对应隐藏的内容,在进行样式设置,如果没有生效,考虑使用!important。

代码:
html 复制代码
.is-phone-hide {
  display: block;
}

.uni-pagination {
  font-size: 24rpx;

  .uni-pagination__num-tag {
    margin: 0 20rpx;
  }

  .uni-pagination__num {
    display: inline-block;
  }
}

效果展示:

CSS全部代码:
html 复制代码
.uni-container {
  margin-top: 60rpx;

  .example-demonstration {
    height: 590rpx;
  }

  .uni-table {
    table-layout: fixed;
    // height: 15.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

    .uni-table-td {
      table-layout: inherit;
      overflow: hidden;
      text-overflow: ellipsis; //省略号表示
      white-space: nowrap; //不换行
    }

    .uni-table-th {
      width: 360rpx; // !important
      box-sizing: content-box;
    }

    .taxId {
      padding-left: 60rpx;
      width: 240rpx;
    }

    uni-view {
      overflow: hidden;
      width: 100%;
      text-overflow: ellipsis; //省略号表示
      white-space: nowrap; //不换行
    }


    .first {
      width: 120rpx;
      // display: flex;
      position: fixed;
      background-color: #FFFAF2;
      z-index: 10;
    }

    .fixed-th {
      width: 77rpx;
    }


  }

  .is-phone-hide {
    display: block;
  }

  .uni-pagination {
    font-size: 24rpx;

    .uni-pagination__num-tag {
      margin: 0 20rpx;
    }

    .uni-pagination__num {
      display: inline-block;
    }
  }

}

以上内容参考:CSS table-layout 属性 | 菜鸟教程uni-app官网

相关推荐
独孤求败Ace1 小时前
第40天:Web开发-JS应用&VueJS框架&Vite构建&启动打包&渲染XSS&源码泄露&代码审计
前端·javascript·vue.js
天若子1 小时前
flutter ListView Item复用源码解析
前端·flutter
文城5214 小时前
HTML-day1(学习自用)
前端·学习·html
阿珊和她的猫4 小时前
Vue 和 React 的生态系统有哪些主要区别
前端·vue.js·react.js
偷光4 小时前
深度剖析 React 的 useReducer Hook:从基础到高级用法
前端·javascript·react.js
The_era_achievs_hero5 小时前
动态表格html
前端·javascript·html
仧凵5 小时前
uniapp中使用uCharts折线图X轴数据间隔显示
uni-app
Thomas_YXQ5 小时前
Unity3D Shader 简析:变体与缓存详解
开发语言·前端·缓存·unity3d·shader
2201_756942646 小时前
react入门笔记
javascript·笔记·react.js
傻小胖6 小时前
ES6 Proxy 用法总结以及 Object.defineProperty用法区别
前端·javascript·es6