原生微信小程序-编写表格-可横向、纵向拖动

效果:

xml文件

<!-- 表格 -->
<view class="table">
  <!-- 整体横向滑动 -->
  <scroll-view class="tableX" scroll-x>
    <!-- 表头 -->
    <view class="tr">
      <view
        wx:for="{{columns}}"
        wx:for-item="column"
        wx:key="index"
        style="width:{{column.width || '200rpx'}}"
        class="th"
        >{{column.title}}
      </view>
    </view>
    <!-- 内容 -->
    <!-- 除表头外纵向滑动 -->
    <scroll-view class="tableY" scroll-y>
      <view class="tr" wx:for="{{tableData}}" wx:for-item="table" wx:key="index">
        <view
          style="border-bottom:{{index===tableData.length-1? 'none':'1px solid #DBDBDB'}};width:{{columnItem.width || '200rpx'}}"
          class="{{columnItem.class? 'td '+columnItem.class : 'td' }}"
          wx:for="{{columns}}"
          wx:for-item="columnItem"
          wx:for-index="columnIndex"
          wx:key="columnIndex"
          >{{table[columnItem.key]}}
        </view>
      </view>
    </scroll-view>
  </scroll-view>
</view>

wxss文件:

/* 项目表格 */
.table {
  background: #FFFFFF;
  /* box-shadow: 0px 0px 10rpx 0px rgba(32,76,131,0.12); */
  /* border-radius: 20rpx ; */
  box-sizing: border-box;
  margin: 0 10rpx;
}
.tableY {
  height: 300rpx;
}
.tr, .tableY {
  width: 1500rpx;
}
.tr {
  display: flex;
}
.th{
  padding: 8rpx;
  border: 1px solid rgb(219, 218, 218);
  background-color: rgb(241, 241, 241);
  text-align: center;
  font-weight: bold;
  font-size: 20rpx;
  font-weight: 400;
  color: #000000;
}
.td {
  padding: 8rpx;
  overflow-x: scroll;
  white-space: nowrap;
  border: 1rpx solid rgb(219, 218, 218);
  text-align: center;
  font-size: 18rpx;
  font-weight: 400;
  color: #666666;
  width: 401rpx;
}

js文件:

 data: {
    tableData: [
      {
        MONTH2:"0",
      SITE2:"0",
      TX2:"0",
      WORK_NO:"0", 
      WORK_NAME:"0", 
      TOTAL_SCORE:"0", 
      JF_SOUR:"0",
      ORDER_NO:"0",
      CALL_NO:"0",
      VOICE_NO:"0", 
      REASON:"0",
      CLASS2:"0", 
      SCORE:"0"
      },
    ],
    columns: [
      {title: '***', key: 'MONTH2', width: '400rpx'}, 
      {title: '***', key: 'SITE2', width: '400rpx'}, 
      {title: '***', key: 'TX2', width: '400rpx'}, 
      {title: '***', key: 'WORK_NO', width: '400rpx'}, 
      {title: '***', key: 'WORK_NAME', width: '400rpx'}, 
      {title: '***', key: 'TOTAL_SCORE', width: '400rpx'}, 
      {title: '***', key: 'JF_SOUR', width: '400rpx'}, 
      {title: '***', key: 'ORDER_NO', width: '400rpx'}, 
      {title: '***', key: 'CALL_NO', width: '400rpx'}, 
      {title: '***', key: 'VOICE_NO', width: '400rpx'}, 
      {title: '***', key: 'REASON', width: '400rpx'}, 
      {title: '***', key: 'CLASS2', width: '400rpx'}, 
      {title: '***', key: 'SCORE', width: '400rpx'}, 
    ],
  },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值