<template>
<div class="hello">
<el-table
:data="tableData"
:span-method="arraySpanMethod"
border
style="width: 100%">
<el-table-column
prop="id"
label="ID"
width="180">
</el-table-column>
<el-table-column
prop="region"
label="地區(qū)">
</el-table-column>
<el-table-column
prop="type"
label="類型">
</el-table-column>
<el-table-column
prop="company.name"
label="企業(yè)名稱">
</el-table-column>
</el-table>
</div>
</template>
<script>
// import VueGridLayout from 'vue-grid-layout'
export default {
name: 'HelloWorld',
data() {
return {
table: [
{
id: 1,
region: '深圳',
type: '外貿(mào)',
company: [
{ name: '深圳外貿(mào)公司1' },
{ name: '深圳外貿(mào)公司2' },
{ name: '深圳外貿(mào)公司3' },
{ name: '深圳外貿(mào)公司4' }
]
},
{
id: 2,
region: '北京',
type: '金融',
company: [
{ name: '北京金融公司1' },
{ name: '北京金融公司2' },
{ name: '北京金融公司3' }
]
},
{
id: 2,
region: '上海',
type: '金融',
company: [{ name: '上海金融公司1' }, { name: '上海金融公司2' }]
}
],
tableData: [], //表格數(shù)據(jù)
arr: [] //合并參數(shù)
}
},
created() {
this.initData(this.table)
},
methods: {
// 初始化數(shù)據(jù)
initData(data) {
console.log(11, data)
this.tableData = []
const tempdata = data.filter(item => item.company)
let s = 0
tempdata.forEach((item, i, data) => {
item.company.forEach(e => {
this.tableData.push({
id: item.id,
region: item.region,
type: item.type,
company: e
})
})
if (this.arr.length) {
s = this.arr[this.arr.length - 1].row + data[i - 1].company.length
}
this.arr.push({
row: s, // 合并的起始行
index: item.company.length // 合并的行數(shù)
})
})
},
arraySpanMethod({ row, column, rowIndex, columnIndex }) {
if (columnIndex === 0 || columnIndex === 1 || columnIndex === 2) {
let obj = []
this.arr.forEach(item => {
if (rowIndex === item.row) {
obj = [item.index, 1]
}
})
return obj
}
}
}
}
</script>
element-ui表格單元格合并
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 轉(zhuǎn)載博客--Evermenot(已親自驗(yàn)證有效) 在使用element-ui 的表格式涉及到了單元格合并問(wèn)題,實(shí)際...
- npm install --save xlsx file-saver 創(chuàng)建@/vendor/Export2Exce...
- 實(shí)現(xiàn)效果圖: ?json: 頁(yè)面源碼:? 控制單元格合并需要span-method(官網(wǎng)) 2018-12-26 ...
- 前言 在使用ElementUI過(guò)程中,表格的使用占了很大一部分,但是使用起來(lái)總感覺(jué)不方便,而且部分想要的功能也沒(méi)有...