vue树形table

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vue树形table相关的知识,希望对你有一定的参考价值。

参考技术A 关键词:vue、table、动态数据

<template>

  <div>

    <el-table

      :data="tableData"

      show-summary

      :span-method="getSpans"

      :summary-method="getSummaries"

      border

      style="width: 100%; margin-top: 20px"

    >

      <el-table-column prop="TenantryName" label="数据1"></el-table-column>

      <el-table-column prop="Name" label="数据2"></el-table-column>

      <el-table-column prop="StartTime" label="数据3"></el-table-column>

      <el-table-column prop="EffectTime" label="数据4"></el-table-column>

      <el-table-column prop="RentPeriod" label="数据6"></el-table-column>

      <el-table-column prop="Money" label="数据7"></el-table-column>

      <el-table-column prop="PeriodStartTime" label="数据8"></el-table-column>

    </el-table>

  </div>

</template>

<script>

let preproperty = undefined;

export default

  data()

    return

      spanArr: [],

      pos: 0,

      matrix: [

        [10, 0, 0, 0, 0, 0, 0, 0, 0, 0],

        [4, 0, 0, 0, 4, 0, 0, 0, 2, 0],

        [4, 0, 0, 0, 4, 0, 0, 0, 2, 0],

        [4, 0, 0, 0, 4, 0, 0, 0, 2, 0],

        [4, 0, 0, 0, 4, 0, 0, 0, 2, 0],

        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],

        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],

        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],

        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],

        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],

        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

      ],

      tableData: [

       

          ID: "a2c4a0d3-d958-4a4d-6fcc-08d72ebd8d7d",

          FirstPartyOrganizationID:

            "9528cac9-0efe-4f31-a207-d9f11dba0510",

          SecondPartyOrganizationID:

            "347292f0-9f22-4c41-a2da-ee17e5dc495a",

          TenantryName: "111",

          Name: "2",

          StartTime: "2019-09-01T00:00:00",

          EndTime: "2029-09-01T00:00:00",

          PeriodStartTime: "2019-09-02T00:00:00",

          PeriodEndTime: "2020-08-31T23:59:59",

          RentPeriod: 1,

          Money: 500.0,

          PaymentTime: "2020-09-01T00:00:00",

          EffectTime: "2019-09-01T00:00:00"

        ,

       

          ID: "2ffe43bf-9048-40eb-6fcd-08d72ebd8d7d",

          FirstPartyOrganizationID:

            "9528cac9-0efe-4f31-a207-d9f11dba0510",

          SecondPartyOrganizationID:

            "347292f0-9f22-4c41-a2da-ee17e5dc495a",

          TenantryName: "嵩明县园区",

          Name: "2",

          StartTime: "2019-09-01T00:00:00",

          EndTime: "2029-09-01T00:00:00",

          PeriodStartTime: "2020-09-01T00:00:00",

          PeriodEndTime: "2021-09-01T00:00:00",

          RentPeriod: 2,

          Money: 500.0,

          PaymentTime: "2021-09-01T00:00:00",

          EffectTime: "2019-09-01T00:00:00"

        ,

       

          ID: "7d11d14e-ec5d-4c5c-6fce-08d72ebd8d7d",

          FirstPartyOrganizationID:

            "9528cac9-0efe-4f31-a207-d9f11dba0510",

          SecondPartyOrganizationID:

            "347292f0-9f22-4c41-a2da-ee17e5dc495a",

          TenantryName: "嵩明县园区",

          Name: "2",

          StartTime: "2019-09-01T00:00:00",

          EndTime: "2029-09-01T00:00:00",

          PeriodStartTime: "2021-09-01T00:00:00",

          PeriodEndTime: "2022-09-01T00:00:00",

          RentPeriod: 3,

          Money: 1050.0,

          PaymentTime: "2022-09-01T00:00:00",

          EffectTime: "2019-09-01T00:00:00"

        ,

       

          ID: "15742d1b-74e4-41cf-6fcf-08d72ebd8d7d",

          FirstPartyOrganizationID:

            "9528cac9-0efe-4f31-a207-d9f11dba0510",

          SecondPartyOrganizationID:

            "347292f0-9f22-4c41-a2da-ee17e5dc495a",

          TenantryName: "嵩明县园区",

          Name: "2",

          StartTime: "2019-09-01T00:00:00",

          EndTime: "2029-09-01T00:00:00",

          PeriodStartTime: "2022-09-01T00:00:00",

          PeriodEndTime: "2023-09-01T00:00:00",

          RentPeriod: 4,

          Money: 1050.0,

          PaymentTime: "2023-09-01T00:00:00",

          EffectTime: "2019-09-01T00:00:00"

        ,

       

          ID: "76c42b89-1009-44ea-6fd6-08d72ebd8d7d",

          FirstPartyOrganizationID:

            "9528cac9-0efe-4f31-a207-d9f11dba0510",

          SecondPartyOrganizationID:

            "347292f0-9f22-4c41-a2da-ee17e5dc495a",

          TenantryName: "嵩明县园区",

          Name: "2",

          StartTime: "2019-09-01T00:00:00",

          EndTime: "2024-09-01T00:00:00",

          PeriodStartTime: "2019-09-01T00:00:00",

          PeriodEndTime: "2020-08-31T23:59:59",

          RentPeriod: 1,

          Money: 10000.0,

          PaymentTime: "2020-09-01T00:00:00",

          EffectTime: "2019-09-01T00:00:00"

        ,

       

          ID: "bcd5c0f3-178d-452e-6fd7-08d72ebd8d7d",

          FirstPartyOrganizationID:

            "9528cac9-0efe-4f31-a207-d9f11dba0510",

          SecondPartyOrganizationID:

            "347292f0-9f22-4c41-a2da-ee17e5dc495a",

          TenantryName: "嵩明县园区",

          Name: "2",

          StartTime: "2019-09-01T00:00:00",

          EndTime: "2024-09-01T00:00:00",

          PeriodStartTime: "2020-09-01T00:00:00",

          PeriodEndTime: "2021-09-01T00:00:00",

          RentPeriod: 2,

          Money: 10000.0,

          PaymentTime: "2021-09-01T00:00:00",

          RentState: 0,

          RentStateText: "未交付",

          EffectTime: "2019-09-01T00:00:00"

        ,

      ]

    ;

  ,

  methods:

    getSpans( row, column, rowIndex, columnIndex )

      if (!column.property)

        return

          rowspan: 1,

          colspan: 1

       

     

      let colspan = this.matrix[columnIndex][rowIndex] == 0 ? 0 : 1;

      return

        rowspan: this.matrix[columnIndex][rowIndex],

        colspan: colspan

      ;

    ,

    objectSpanMethod( row, column, rowIndex, columnIndex )

      row[column.property];

      return this.getRowColSpans(rowIndex, column.property);

    ,

    getSummaries(param)

      const columns, data = param;

      const sums = [];

      columns.forEach((column, index) =>

        if (index === 0)

          sums[index] = "总";

          return;

       

        const values = data.map(item => Number(item[column.property]));

        if (!values.every(value => isNaN(value)))

          sums[index] = values.reduce((prev, curr) =>

            const value = Number(curr);

            if (!isNaN(value))

              return prev + curr;

            else

              return prev;

           

          , 0);

          sums[index] += " 个";

        else

          sums[index] = " ";

       

      );

      return sums;

   

  ,

  mounted()

;

</script>

Vue+element使用table实现树形菜单

参考技术A 使用一维数组现实树形菜单,根据菜单的层级使用动态样式缩进实现视觉上的层级效果

utils两个工具类

以上是关于vue树形table的主要内容,如果未能解决你的问题,请参考以下文章

vue树形三级分层控件的使用

vue-table-with-tree-grid的树形表格组件如何使用

使用vue-table-with-tree-grid的树形表格组件

使用vue-table-with-tree-grid的树形表格组件

使用vue-table-with-tree-grid的树形表格组件

VUE项目实战38实现商品分类的树形表格