最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to make a table row clickable and expand the row - vue.js - element-ui - Stack Overflow

programmeradmin3浏览0评论

I am using table that has expandable row feature. The row expands when the expand icon is clicked, you can check the example HERE. But, what I am trying to make is, the entire row clickable and toggle expand and collapse the row just like it works when the expand icon is clicked.

Please help.

Here is my markup:

<template lang="pug">
  el-table(:data="tableData")
    el-table-column(label="Employee Name", prop="userName")
    el-table-column(label="Company Name", prop="companyName")
    el-table-column(type="expand", align="right" )
      template(slot-scope="props")
        p User Name: {{ props.row.userName }}
        p Company Name: {{ props.rowpanyName }}
</template>

I am using table that has expandable row feature. The row expands when the expand icon is clicked, you can check the example HERE. But, what I am trying to make is, the entire row clickable and toggle expand and collapse the row just like it works when the expand icon is clicked.

Please help.

Here is my markup:

<template lang="pug">
  el-table(:data="tableData")
    el-table-column(label="Employee Name", prop="userName")
    el-table-column(label="Company Name", prop="companyName")
    el-table-column(type="expand", align="right" )
      template(slot-scope="props")
        p User Name: {{ props.row.userName }}
        p Company Name: {{ props.row.companyName }}
</template>
Share Improve this question edited Aug 27, 2018 at 5:53 Syed asked Aug 27, 2018 at 5:31 SyedSyed 16.5k13 gold badges126 silver badges157 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 20

Alright, I figured out the solution and answering my own question :)

Markup:

<template lang="pug">
  el-table(:data="tableData", @row-click="rowClicked", ref="tableData").clickable-rows
    el-table-column(label="Employee Name", prop="userName")
    el-table-column(label="Company Name", prop="companyName")
    el-table-column(type="expand", align="right" )
      template(slot-scope="props")
        p User Name: {{ props.row.userName }}
        p Company Name: {{ props.row.companyName }}
</template>

Script:

<script>
  export default {
    methods: {
      rowClicked(row) {
        this.$refs.tableData.toggleRowExpansion(row);
      }
    }
  }
</script>

Style - scss

// click-able rows
.clickable-rows {
  tbody tr td {
    cursor: pointer;
  }

  .el-table__expanded-cell {
    cursor: default;
  }
}

I think there is better way to do so We have row-key in el-table, and expand-row-keys So every time you click you can change current expanded row even you can create behavior that "expan-one-at-a-time" Like: :expand-row-keys="[currentExpandedRow]"

发布评论

评论列表(0)

  1. 暂无评论