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官网

相关推荐
昨天;明天。今天。7 分钟前
案例-任务清单
前端·javascript·css
一丝晨光33 分钟前
C++、Ruby和JavaScript
java·开发语言·javascript·c++·python·c·ruby
Front思35 分钟前
vue使用高德地图
javascript·vue.js·ecmascript
zqx_71 小时前
随记 前端框架React的初步认识
前端·react.js·前端框架
惜.己2 小时前
javaScript基础(8个案例+代码+效果图)
开发语言·前端·javascript·vscode·css3·html5
什么鬼昵称2 小时前
Pikachu-csrf-CSRF(get)
前端·csrf
长天一色2 小时前
【ECMAScript 从入门到进阶教程】第三部分:高级主题(高级函数与范式,元编程,正则表达式,性能优化)
服务器·开发语言·前端·javascript·性能优化·ecmascript
NiNg_1_2343 小时前
npm、yarn、pnpm之间的区别
前端·npm·node.js
秋殇与星河3 小时前
CSS总结
前端·css
NiNg_1_2343 小时前
Vue3 Pinia持久化存储
开发语言·javascript·ecmascript