elementui的table根據(jù)是否符合需求合并列的實現(xiàn)代碼
更新時間:2024年03月27日 12:23:05 作者:EstherNi
這篇文章主要介紹了elementui的table根據(jù)是否符合需求合并列的實現(xiàn)代碼,代碼簡單易懂,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧
elementui的table根據(jù)是否符合需求合并列

<el-table :data="tableData" border style="width: 100%;" :span-method="objectSpanMethodAuto">
<!-- 空狀態(tài) -->
<template slot="empty">
<div><img src="@/assets/images/noData.png" /></div>
<span>暫無數(shù)據(jù)</span>
</template>
<el-table-column type="index" label="序號" width="80" align="center">
</el-table-column>
<el-table-column label="年度" align="center" prop="year">
</el-table-column>
<el-table-column prop="regionName" label="行政區(qū)劃" align="center">
</el-table-column>
<el-table-column align="center">
<template slot="header">
<div class="header-con">(萬人)</div>
<div class="header-name">農(nóng)業(yè)人口數(shù)量</div>
</template>
<template slot-scope="scope">
<div>{{ scope.row.ruralPopNum }}</div>
</template>
</el-table-column>
<el-table-column align="center">
<template slot="header">
<div class="header-con">(萬人)</div>
<div class="header-name">城鎮(zhèn)人口數(shù)量</div>
</template>
<template slot-scope="scope">
<div>{{ scope.row.urbanPopNum }}</div>
</template>
</el-table-column>
<el-table-column label="操作" align="center">
<template slot-scope="{ row }">
<el-button type="text" size="small" class="operation" style="color: #2372ed;" @click="handleEditTable(row)">編輯</el-button>
<el-button type="text" size="small" class="operation" style="color: #2372ed;" @click="handleDelete(row)">刪除</el-button>
</template>
</el-table-column>
</el-table>data: function () {
return {
spanArr:[],
tableData:[]
}
}getList() {
getPopList(this.query).then((res) => {
this.totalCount = res.total;
this.tableData = res.rows;
let contactDot = 0;
let spanArr = [];
this.tableData.forEach((item, index) => {
if (index === 0) {
console.log(spanArr);
spanArr.push(1);
} else {
if (item.year === this.tableData[index - 1].year) {
spanArr[contactDot] += 1;
spanArr.push(0);
} else {
contactDot = index;
spanArr.push(1);
}
}
});
this.spanArr = spanArr;
});
}, // 合并行
objectSpanMethodAuto({ row, column, rowIndex, columnIndex }) {
console.log("點擊:", row, column, rowIndex, columnIndex);
if (columnIndex == 1 || columnIndex == 5) {
if (this.spanArr[rowIndex]) {
return {
rowspan: this.spanArr[rowIndex],
colspan: 1,
};
} else {
return {
rowspan: 0,
colspan: 0,
};
}
}
},到此這篇關于elementui的table根據(jù)是否符合需求合并列的文章就介紹到這了,更多相關elementui的table合并列內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:
- elementui?el-table底層背景色修改簡單方法
- 關于ElementUI el-table 鼠標滾動失靈的問題及解決辦法
- Vue+EleMentUI實現(xiàn)el-table-colum表格select下拉框可編輯功能實例
- elementUI中el-table表頭和內(nèi)容全部一行顯示完整的方法
- 使用elementUI table展開行內(nèi)嵌套table問題
- Vue?ElementUI在el-table中使用el-popover問題
- elementUI的table表格改變數(shù)據(jù)不更新問題解決
- 解決elementUI 切換tab后 el_table 固定列下方多了一條線問題
相關文章
vue3利用v-model實現(xiàn)父子組件之間數(shù)據(jù)同步的代碼詳解
在Vue 3中,v-model這一指令也得到了升級,使得父子組件之間的數(shù)據(jù)同步變得更加容易和靈活,本文將探討一下Vue 3中如何利用v-model來實現(xiàn)父子組件之間的數(shù)據(jù)同步,需要的朋友可以參考下2024-03-03

