vue+el-table實現(xiàn)合并單元格
更新時間:2021年09月29日 09:24:37 作者:linlinlinhtml_
這篇文章主要為大家詳細介紹了vue+el-table實現(xiàn)合并單元格,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了el-table實現(xiàn)合并單元格的具體代碼,供大家參考,具體內(nèi)容如下
el-table合并單元格(vue+element)
- 先在el-table放入:span-method="arraySpanMethod"
<el-table :header-cell-style="{background:'#eef1f6',color:'#606266'}" :data="merchantList" border :span-method="arraySpanMethod"> <el-table-column align="center" prop="provinceName" label="省份"> </el-table-column> <el-table-column align="center" label="代理商名稱"> <template scope="scope"> <span>{{scope.row.parentMerchantName == scope.row.merchantName ? '---' : scope.row.parentMerchantName}}</span> </template> </el-table-column> <el-table-column align="center" prop="cityName" label="市"> </el-table-column> <el-table-column align="center" prop="countryName" label="區(qū)"> </el-table-column> <el-table-column align="center" prop="merchantName" label="門店"> </el-table-column> </el-table>
在methods中寫入方法:
//合并單元格 arraySpanMethod ({ row, column, rowIndex, columnIndex }) { if (columnIndex === 0) {//第一列的合并方法,省 const _row_1 = this.provinceArr[rowIndex]; const _col_1 = _row_1 > 0 ? 1 : 0; //如果被合并了_row=0則它這個列需要取消 return { rowspan: _row_1, colspan: _col_1 } } }, //初始化 merageInit () { this.provinceArr = [] this.provincePos = 0 }, //要合并的數(shù)組的方法 merage () { this.merageInit() for (var i = 0; i < this.merchantList.length; i++) { if (i === 0) { //第一行必須存在 this.provinceArr.push(1) this.provincePos = 0 } else { // 判斷當前元素與上一個元素是否相同 this.provincePos是provinceArr內(nèi)容的序號 //省 if (this.merchantList[i].provinceName === this.merchantList[i - 1].provinceName) { this.provinceArr[this.provincePos] += 1 this.provinceArr.push(0) } else { this.provinceArr.push(1) this.provincePos = i } } } },
結(jié)果展示:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue實現(xiàn)路由跳轉(zhuǎn)動態(tài)title標題信息
這篇文章主要介紹了vue實現(xiàn)路由跳轉(zhuǎn)動態(tài)title標題信息,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-06-06Vue3?封裝一個支持輸入和單/多選InputSelect組件-Antd詳解
Antd的Select組件默認不支持作為輸入框使用或手動添加選項,為了實現(xiàn)這一功能,我們封裝了一個通用組件,支持單選和多選模式,并允許用戶在組件失焦時手動輸入選項,主要通過定義searchText存儲輸入數(shù)據(jù),感興趣的朋友跟隨小編一起看看吧2024-09-09