
vue3+element plus el-table嵌套表格、展开行
vue3、elementPlus 如何完成嵌套表格、展开行
·
问题前提:需要展示的表格内容其中包括包含关系,需要使用二级嵌套表格进行展示,因为展示的一级表格和二级表格的表头内容和展示内容并不相同,使用el-table原本的树形数据不能满足,使用el-table展开行,利用展开功能完成包含关系内容的展开
解决过程:最后的实现效果是点击一级表格某一行的展开按钮时,会展开该行下包含的二级表格内容
解决结果:通过设置 type="expand" 和 slot 可以开启展开行功能, el-table-column 的模板会被渲染成为展开行的内容,展开行可访问的属性与使用自定义列模板时的 slot 相同,要加row-key属性,不加会出现闪展开闪关闭的情况,default-expand-all属性定义默认展开或者关闭,在点击展开或者关闭时,触发@expand-change,可以在点击展开时再请求获取展开内容
<el-table
border
:data="state.tableData.records"
ref="tableDOM"
stripe
:cell-style="{ 'text-align': 'center' }"
row-key="id"
:default-expand-all="false"
@expand-change="expandChange"
>
<el-table-column type="expand">
<template #default="props">
//展开内容
<el-table
:data="props.row.children"
ref="tableDOM"
stripe
:cell-style="{ 'text-align': 'center' }"
max-height="500"
>
<el-table-column
prop="id"
label="序号"
width="80"
:show-overflow-tooltip="true"
>
<template #default="scopes">
{{ scopes.$index + 1 }}
</template>
</el-table-column>
<el-table-column
prop="time"
label="时间"
min-width="150"
:show-overflow-tooltip="true"
/>
<el-table-column
prop="weatherText"
label="天气"
width="100"
:show-overflow-tooltip="true"
/>
</el-table>
</template>
</el-table-column>
</el-table>
更多推荐
所有评论(0)