框架中提供了合計的屬性方法,這樣能夠進行數值求和及自定義求和,可是,合計那一欄不能添加點擊跳轉功能,結構默認排到最底行,不知足需求html
經過給table傳入span-method方法能夠實現合併行或列,方法的參數是一個對象,裏面包含當前行row、當前列column、當前行號rowIndex、當前列號columnIndex四個屬性。該函數能夠返回一個包含兩個元素的數組,第一個元素表明rowspan,第二個元素表明colspan。 也能夠返回一個鍵名爲rowspan和colspan的對象。element-ui
解決思路:數組
<el-table ref="tableData" tooltip-effect="dark" style="width: 100%" border :data="tableData" v-loading="loading" :span-method="arraySpanMethod"> <el-table-column type="index" label="序號" align="center" width="55" :index="indexFun"></el-table-column> <el-table-column prop="name" align="center" label="姓名"> <template slot-scope="scope"> <el-button type="text" size="small" @click="goLink(scope.row)">{{scope.row.name}}</el-button> </template> </el-table-column> </el-table>
// 插入合計的數據 summaryFun(){ var obj = [「合計」,......]; this.tableData.unshift(obj); }, // 合併合計第一行 arraySpanMethod({ row, column, rowIndex, columnIndex }) { if (rowIndex === 0) { if (columnIndex === 0) { return [0, 0]; } else if (columnIndex === 1) { return [1, 2]; } } }, // 表格序號 除去合計從第一開始,以下圖 indexFun (index) { return index; }, // 點擊合計進行跳轉 goLink(row){ if(row.id == "合計"){window.loaction.href=""} }
arraySpanMethod({ row, column, rowIndex, columnIndex }) { // 合併第一行 if (rowIndex === 0) { if (columnIndex === 0) { return [0, 0]; } else if (columnIndex === 1) { return [1, 3]; } else if (columnIndex === 2) { return [0, 0]; } } },
arraySpanMethod({ row, column, rowIndex, columnIndex }) { // 合併第一行 // if (rowIndex === 0) { // if (columnIndex === 0) { // return [0, 0]; // } else if (columnIndex === 1) { // return [0, 0]; // }else if (columnIndex === 2) { // return [1, 3]; // } // } if (rowIndex === 0) { if (columnIndex === 0) { return [0, 0]; } else if (columnIndex === 1) { return [0, 0]; }else if (columnIndex === 2) { return [1, 4]; }else if (columnIndex === 3) { return [0, 0]; } } },