• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

joer717

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

element table总结

设置table的样式

          :row-style="rowClass"
          :cell-style="cellClass"
          :header-cell-style="{textAlign:'center',background:'#ebeef4'}"
    rowClass ({ row, index }) {
      if (row.workarea === '小计' || row.workarea === '总计') {
        return 'font-weight:bold; color:red; text-align:center'
      } else {
        return 'text-align:center'
      }
    },
    cellClass ({ row, column, rowIndex, columnIndex }) {
      if (row.workarea === '小计' || row.workarea === '总计') {
        return 'font-weight:bold; color:#0a8dec;text-align:center'
      } else {
        return 'text-align:center'
      }
    },
//貌似设置字体颜色啥的得用cellcalass

合并单元格

//:span-method="objectSpanMethod" 写在table里面
    objectSpanMethod ({ row, column, rowIndex, columnIndex }) {
//如果是第一列的话 spanArr放的是第一列应该合并第几行的
      if (columnIndex === 0) {
        const _row = this.spanArr[rowIndex]
        const _col = _row > 0 ? 1 : 0
        return {
          rowspan: _row,
          colspan: _col
        }
      }
//如果是第二列的话 spanArr放的是第二列应该合并第几行的
      if (columnIndex === 1) {
        const _row = this.spanArr1[rowIndex]
        const _col = _row > 0 ? 1 : 0
        return {
          rowspan: _row,
          colspan: _col
        }
      }
    }

//获取合并数据
        let contactDot = 0
        let contactDot1 = 0
        this.tableData.forEach((item, index) => {
          item.index = index
          if (index === 0) {
            this.spanArr.push(1)
            this.spanArr1.push(1)
          } else {
            if (item.use === this.tableData[index - 1].use) {
// 如果第一行的数据等于他后面那一行的数据 数组+1 后面push个0
              this.spanArr[contactDot] += 1
              this.spanArr.push(0)
            } else {
//否则不合并
              this.spanArr.push(1)
              contactDot = index
            }
            if (item.type === this.tableData[index - 1].type) {
              this.spanArr1[contactDot1] += 1
              this.spanArr1.push(0)
            } else {
              this.spanArr1.push(1)
              contactDot1 = index
            }
          }
        })

 

posted on 2019-07-08 10:07  joer717  阅读(434)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3