el-table使用递归组件实现多级表头

6 篇文章 0 订阅
1 篇文章 0 订阅
<el-table
 ref="multipleTable"
 :data="tableData"
 max-height="430"
 style="width: 100%"
>
 <el-table-column
   prop="schoolName"
   label="学科"
   align="center"
   :min-width="firstColumnWidth" fixed>
   <template slot="header" slot-scope="scope">
     {{ firstColumn(scope) }}
   </template>
   <template slot-scope="scope">
     <span class="table_column_first">{{ scope.row.schoolName }}</span>
   </template>
 </el-table-column>
 <column-item v-for="(item,index) in tableTitle" :key="index" :col="item"></column-item>
</el-table>

其中column-item是递归组件实现的多级表头,代码如下:
columnItem.vue组件代码(其中在后台返回的递归数据中,如果children还有下一级数据,则在组件中使用column-item继续使用该组件):

<template>
  <el-table-column
    :prop="col.attribute"
    :label="col.title"
    :sortable="!col.children||col.children.length==0?'custom':false"
    align="center">
    <template v-if="col.children">
      <column-item v-for="(item, index) of col.children" :key="index" :col="item"></column-item>
    </template>
    <template slot-scope="scope">
      <span :class="{can_click:scope.row[col.attribute].statisticsType==1}">{{ scope.row[col.attribute].valueStr }}</span>
    </template>
  </el-table-column>
</template>

<script>
    export default {
      name: "columnItem",
      props: {
        col: {
          type: Object,
        }
      }
    }
</script>

<style scoped>
  @import url("../../../common/css/common.css");
  /deep/ .el-table .cell {
    width: auto;
    padding: 0;
    word-break: break-word;
    line-height: 20px;
    font-family: Helvetica, "Arial", 'Microsoft YaHei';
  }
  .el-table span {
    display: inline-block;
    /*max-width: 86px;
    min-width: 60px;*/
    width: 100%;
    text-align: right;
  }
</style>

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值