1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > element-ui 表格(table)合并表头下面合并列且可以收缩展开

element-ui 表格(table)合并表头下面合并列且可以收缩展开

时间:2021-05-13 21:47:26

相关推荐

element-ui 表格(table)合并表头下面合并列且可以收缩展开

百度了一大堆,发现了首行不能合并,想到了用dom做,找到了下面这个链接

要点记录:

1、表头合并 —— 给table添加属性:header-cell-style="headerStyle",里面给首行设置跨行

element-ui表头合并 - ^Mao^ - 博客园

2、表内合并 ——给table添加属性:span-method="arraySpanMethod",里面设置合并

Element - The world's most popular Vue UI framework

3、表收缩 ——给table添加属性:tree-props="childrenObj", 表示表格可展开,不要用原本的树形结构,因为我们有合并,直接用elementui自带的第一行合并带子级数据,展开后子级插在合并的中间,所以我们采用:合并的那一列标记有没有子级,合并的最后一列增加子级数据,自己做收缩展开功能

基于element-ui的table实现树级表格操作及单元格合并_trottoir的博客-CSDN博客

全部代码如下:

<el-tablev-if="!listLoading"ref="table":data="listAttr"fitstripe:height="height":tree-props="childrenObj":header-cell-style="headerStyle"class="width-per-100 margin-top-10":span-method="arraySpanMethod":row-key="getRowKey"><el-table-column align="center" width="250" label="地区及急救分中心"><el-table-column min-width="170" align="left"><template slot-scope="scope"><span v-if="scope.row.hasChildren" class="arrow-icon" @click="toggleRowExpansion(scope.row)"><i :class="scope.row.isExpand ? 'el-icon-caret-bottom' : 'el-icon-caret-right'" /></span><span>{{ scope.row.name | noDataFilterLine }}</span></template></el-table-column><el-table-column min-width="70" align="center"><template slot-scope="scope">{{ scope.row.type === 1 ? '呼入量' : '出车量' }}</template></el-table-column></el-table-column><el-table-columnv-for="(item, index) in tableLabelList":key="index"align="center":label="item"min-width="80"><template slot-scope="scope">{{ scope.row.list[index] }}</template></el-table-column></el-table>

// 表头跨列 headerStyle({ row, column, rowIndex, columnIndex }) {// 1.1 让第0行的第0列跨2行if (rowIndex === 0 && columnIndex === 0) {this.$nextTick(() => {document.getElementsByClassName(column.id)[0].setAttribute('rowSpan', 2)return {}})}// 1.2 被覆盖的进行隐藏if (rowIndex === 1 && (columnIndex === 0 || columnIndex === 1)) {return {display: 'none'}}return {}},// 合并表格arraySpanMethod({ row, columnIndex, rowIndex }) {// 合并第一列的两行if (columnIndex === 0) {if (rowIndex % 2 === 0) {return {rowspan: 2,colspan: 1}} else {return {rowspan: 0,colspan: 0}}}},// 收缩展开方法toggleRowExpansion(row) {row.isExpand = !row.isExpandconst item = this.listAttr.find(i => {return i.centerId === row.centerId && i.cityCode === row.cityCode && i.index === row.index && i.type === 2})if (this.$refs.table) {this.$refs.table.toggleRowExpansion(item, row.isExpand)}},

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。