el-table表格实现点击展开内嵌表格

html部分

<el-table :data="tableList" row-key="id" ref="tableObj">
            <el-table-column
              show-overflow-tooltip
              label="序号"
              align="left"
              width="50"
              type="index"
            >
            </el-table-column>
            <el-table-column type="expand" class="tetable">
              <template slot-scope="props">
              //内嵌表格数据
                <div class="testdiv" v-if="props.row.isdanju">
                  <el-table
                    class="customer-table"
                    :data="props.row.orderList"
                    :header-cell-style="{ background: '#f8faff' }"
                  >
                    <!-- <el-table-column
                      width="120"
                      show-overflow-tooltip
                      class-name=""
                      label="当前单据"
                    >
                    </el-table-column> -->
                    <el-table-column
                      show-overflow-tooltip
                      label="序号"
                      class-name="second_title"
                      type="index"
                      width="100"
                    >
                    </el-table-column>
                    <el-table-column
                      show-overflow-tooltip
                      label="预约时间"
                      class-name="second_title"
                      prop="applicantTime"
                      width="300"
                    >
                    </el-table-column>
                    <el-table-column
                      show-overflow-tooltip
                      label="预约人"
                      class-name="second_title"
                      prop="applicantUser"
                      width="180"
                    >
                    </el-table-column>
                    <el-table-column
                      prop="flowNumber"
                      show-overflow-tooltip
                      class-name="second_title"
                      label="预约委托单"
                      width="180"
                    >
                    </el-table-column>
                    <el-table-column
                      show-overflow-tooltip
                      class-name="second_title"
                      label="测试内容"
                      width="180"
                    >
                      <template slot-scope="scope">
                        <router-link
                          :to="{
                            path: '/resourceAdministrations/appointmentDetails',
                            query: { id: scope.row.orderId },
                          }"
                        >
                          <el-link :underline="false" type="primary"
                            >查看</el-link
                          >
                        </router-link>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
                //内嵌第二个表格的数据  以此次类推
                <div class="testdiv" v-if="props.row.isceshi">
                  <!-- <p class="title">测试内容</p> -->
                  <el-table
                    class="customer-table"
                    :data="props.row.processList"
                    :header-cell-style="{ background: '#f8faff' }"
                  >
                    <el-table-column
                      show-overflow-tooltip
                      class-name=""
                      label="测试内容"
                      width="100"
                    >
                    </el-table-column>
                    <el-table-column
                      show-overflow-tooltip
                      class-name="second_title"
                      label="序号"
                      type="index"
                      width="100"
                    >
                    </el-table-column>
                    <el-table-column
                      show-overflow-tooltip
                      label="测试类别"
                      class-name="second_title"
                      prop="testType"
                      width="180"
                    >
                    </el-table-column>
                    <el-table-column
                      prop="testTarget"
                      show-overflow-tooltip
                      class-name="second_title"
                      label="测试指标"
                      width="250"
                    >
                    </el-table-column>
                  </el-table>
                </div>
              </template>
            </el-table-column>

            <el-table-column label="车牌号" prop="carPlate" width="" />
            <el-table-column label="测试指标">
              <template slot-scope="scope">
                <div
                  @click="clickButton(scope.row)"
                  style="
                    font-size: 14px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #276afc;
                    cursor: pointer;
                  "
                >
                  <div class="sanjiao" v-show="!scope.row.isceshi">
                    <div>展开</div>
                    <div class="icon"></div>
                  </div>
                  <div class="sanjiao" v-show="scope.row.isceshi">
                    <div>收起</div>
                    <div class="icons"></div>
                  </div>
                </div>
              </template>
            </el-table-column>

            <el-table-column label="测试计划">
              <template slot-scope="scope">
                <div
                  @click="clickButtons(scope.row)"
                  style="
                    font-size: 14px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #276afc;
                    cursor: pointer;
                  "
                >
                  <div class="sanjiao" v-if="!scope.row.isdanju">
                    <div>{{ scope.row.orderNum }}</div>
                    <div class="icon"></div>
                  </div>
                  <div class="sanjiao" v-if="scope.row.isdanju">
                    <div>{{ scope.row.orderNum }}</div>
                    <div class="icons"></div>
                  </div>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <span
                  @click="handleEdit(scope.row, '1')"
                  style="
                    font-size: 14px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #276afc;
                    cursor: pointer;
                  "
                  >详情</span
                >
                <span
                  @click="handleEdit(scope.row, '2')"
                  style="
                    font-size: 14px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    margin-left: 20px;
                    font-weight: 400;
                    color: #276afc;
                    cursor: pointer;
                  "
                  >编辑</span
                >

                <span
                  @click="handleEdit(scope.row, '3')"
                  style="
                    font-size: 14px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    margin-left: 20px;
                    font-weight: 400;
                    color: #fa4b4b;
                    cursor: pointer;
                  "
                  >删除</span
                >
              </template>
            </el-table-column>
          </el-table>

js部分

   //将展开的表格全部收起来
    toggleRowExpansion_forAll(data) {
      data.forEach((item) => {
        this.$refs.tableObj.toggleRowExpansion(item, false);
      });
    },
    //点击可展开项
    clickButton(row) {
      this.toggleRowExpansion_forAll(this.tableList);
      for (const key in this.tableList) {
        if (this.tableList[key].id == row.id) {
          this.$set(this.tableList[key], "isdanju", false);
          this.tableList[key].isceshi = !this.tableList[key].isceshi;
        } else {
          this.$set(this.tableList[key], "isceshi", false);
          this.$set(this.tableList[key], "isdanju", false);
        }
      }
      this.$refs.tableObj.toggleRowExpansion(row);
      if (!row.isceshi && !row.isdanju) {
        this.toggleRowExpansion_forAll(this.tableList);
      }
    },
    handleRow(row, column, event) {
      console.log(row, column, event, "888");
    },
    handleExpandChange(isExpend, expandedRows) {},
    clickButtons(row) {
      this.toggleRowExpansion_forAll(this.tableList);
      for (const key in this.tableList) {
        if (this.tableList[key].id == row.id) {
          this.$set(this.tableList[key], "isceshi", false);
          this.tableList[key].isdanju = !this.tableList[key].isdanju;
        } else {
          this.$set(this.tableList[key], "isceshi", false);
          this.$set(this.tableList[key], "isdanju", false);
        }
      }
      this.$refs.tableObj.toggleRowExpansion(row);
      if (!row.isceshi && !row.isdanju) {
        this.toggleRowExpansion_forAll(this.tableList);
      }
    },

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue.js 中,可以使用 Element UI 中的 el-table 表格组件来实现表格排序。el-table 组件提供了一个 sortable 属性,可以设置表格的排序方式。 以下是一个简单的 el-table 表格排序实现示例: HTML代码: ``` <template> <div> <el-table :data="tableData" :sortable="true"> <el-table-column prop="name" label="姓名" sortable></el-table-column> <el-table-column prop="age" label="年龄" sortable></el-table-column> <el-table-column prop="gender" label="性别" sortable></el-table-column> </el-table> </div> </template> ``` JavaScript代码: ``` <script> export default { data() { return { tableData: [ { name: '张三', age: 20, gender: '男' }, { name: '李四', age: 22, gender: '男' }, { name: '王五', age: 18, gender: '女' } ] } } } </script> ``` 在 el-table 组件中,设置 sortable 属性为 true,然后在每一个 el-table-column 列中设置 sortable 属性即可完成表格排序的功能。在 el-table-column 中设置 prop 属性为表格数据源中的对应属性名,设置 label 属性为列名。 如果需要对表格数据进行默认排序,可以在 el-table 组件中设置 sort-by 和 sort-direction 属性。sort-by 属性为表格数据源中的对应属性名,sort-direction 属性为排序方向,值为 ascending(升序)或 descending(降序)。 ``` <el-table :data="tableData" :sortable="true" :sort-by="'age'" sort-direction="ascending"> ``` 需要注意的是,el-table数据源必须是一个数组,每个元素都是一个对象,对象的属性名对应每一列的 prop 属性值。 这样,就可以通过 el-table 表格组件快速方便地实现表格排序功能了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值