element table多層巢狀顯示的實踐
阿新 • 來源:網路 • 發佈:2021-09-30
有個需求是一個列表,裡面包含多個單子,每個單子可以是唯一,也可以是多個合併之後的,而且每個單子下面顯示的是另外一個表格,來上圖

每行的操作還不一樣,然後通過官網的一些例子總結了一下合併程式碼
<template>
<div class="app-container">
<div>
<el-table
http://www.cppcns.com :data="tableData"
style="width: 100%;margin-bottom: 20px;"
:span-method="arraySpanMethod"
row-key="id"
border
>
<el-table-column type="expand">
<template slot-scope="props">
<el-table
class="table-in-table"
:show-header="false"
:data="props.row.datas"
style="width: 100%;"
row-key="id"
:span-method="arraySpanMethod"
border
>
<el-table-column type="expand">
<template slot-scope="props">
<el-table
class="table-in-table"
:data="props.row.datas"
style="width: 100%;"
row-key="id"
bwww.cppcns.comorder
>
<el-table-column prop="date" label="下單日期" width="180"></el-table-column>
<el-table-column prop="type" label="單據型別" width="180"></el-table-column>
<el-table-column prop="status" label="狀態"></el-table-column>
<el-table-column label="操作" width="120">
<template slot-scope="props">
<el-button type="text" size="small">移除</el-button>
</template>
</el-table-column>
</el-table>
</template>
</el-table-column>
<el-table-column prop="applyNo" label="申請單號" width="132.2"></el-table-column>
<el-table-column prop="name" label="姓名" width="180"></el-table-column>
<el-table-column prop="address" label="地址"></el-table-column>
</el-table>
</template>
</el-table-column>
<el-table-colqtKXjDKZumn prop="applyNo" label="申請單號" width="180"></el-table-column>
<el-table-column prop="name" label="姓名" width="180"></el-table-column>
<el-table-column prop="address" label="地址"></el-table-column>
<el-table-column label="操作" width="120">
<template slot-scope="props">
<el-button type="text" size="small">移除</el-button>
</template>
</el-table-column>
</el-table>
</div>
</div>
</template>
<script>
export default {
name: "name1",components: {},data() {
return {
tableData: [
{
id: 1,applyNo: "202004291234",name: "李四",address: "上海市普陀區金沙江路 1518 弄"
},{
id: 2,applyNo: "202004291235",name: "張三",address: "上海市普陀區金沙江路 1517 弄"
},{
id: 3,applyNo: "202004291236,202004291237",name: "王五",address: "上海市普陀區金沙江路 1519 弄",datas: [
{
id: 31,applyNo: "202004291236",datas: [
{
id: 31,date: "2016-05-01",type: "型別1",status: "已發貨"
},{
id: 32,type: "型別2",status: "未發貨"
}
]
},{
id: 32,applyNo: "202004291237",address: "上海市普陀區金沙江路 1519 弄"
}
]
},{
id: 4,applyNo: "202004291238",name: "趙6六",address: "上海市普陀區金沙江路 1516 弄"
}
]
};
},methods: {
arraySpanMethod({ row,column,rowIndex,columnIndex }) {
if (!row.datas) {
if (columnIndex === 0) {
return [0,0];
} else if (columnIndex === 1) {
return [1,2];
}
}
}
}
};
</script>
<style lang="s" scoped>
.app-container {
::v-deep {
.el-table th {
background: #ddeeff;
}
.el-table__expanded-cell {
border-bottom: 0px;
border-right: 0px;
padding: 0px 0px 0px 47px;
}
}
.table-in-table {
border-top: 0px;
}
}
</style>
注:需要注意一點的是,這裡面的孩子節點不能用children,因為官方預設是children,所以會出現別的下拉元件
設定td寬度的時候,需要注意的是裡面跟外層的差47.8
到此這篇關於element table多層巢狀顯示的實踐的文章就介紹到這了,更多相關element table多層巢狀內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!
