一、eltable合并行太长
在使用eltable时,经常会遇到需要合并行的情况。但是当某行合并内容太长时,就会出现合并行显示不全的情况。解决这个问题可以使用CSS的white-space: nowrap
属性来强制不断行。
.el-table__row,
.el-table__row td,
.el-table__row .cell {
white-space: nowrap;
}
二、eltable合并行多个条件
有些时候需要根据多个条件进行行合并,此时可以使用el-table-column
的span-method
属性来自定义合并规则。在这个方法中,可以根据不同的条件返回不同的合并结果。
<el-table-column prop="name" label="姓名">
<template slot-scope="{row}">
{{ row.name }}
</template>
<span slot="header" :rowspan="2">个人信息</span>
<span slot="footer">合计</span>
<template slot="footer-cell">
{{ tableData.length }}
</template>
<template slot="append">
{{ row.address }}
</template>
<template slot="spanMethod" slot-scope="scope">
<span v-if="scope.row.name==='小红' || (scope.row.name==='小明' && scope.columnIndex===1)" :rowspan="2">{{ scope.row.name }}</span>
<span v-else-if="scope.row.name==='小刚'" :colspan="2">{{ scope.row.name }}</span>
</template>
</el-table-column>
三、eltable合并行错位
在使用合并行时,有时会出现合并后行错位的情况。这种问题通常是因为列的数量不一致导致的。在表格中添加表头列和非合并单元格可以解决这个问题。
<el-table-column label="">
<template slot-scope="{ row }">
{{ row.key }}
</template>
<template slot="header">
序号
</template>
</el-table-column>
四、eltable合并行的样式
合并行的样式可以使用CSS来修改,例如可以给合并的行和单元格添加背景色、边框等。
.el-table__row--merged,
.el-table__row--merged td {
background-color: #f5f7fa;
border-color: #e4e7ed;
}
五、eltable合并行以后样式
有些时候合并行后,行与行之间的间距比较大,这时我们可以通过CSS来调整行的高度来解决。
.el-table__row--merged {
height: 30px;
}
.el-table__row--border {
height: 36px;
}
六、eltable合并后序号
合并行后表格的序号会错乱,可以通过在template
中重新计算序号来解决这个问题。
<el-table-column label="序号" type="index" align="center" width="80">
<template slot-scope="{ $index, $table }">
{{ $table.page.currentPage * $table.page.pageSize - ($table.page.pageSize - 1) + $index }}
</template>
</el-table-column>
七、eltable合并行 斑马纹
在合并行后,表格的斑马线可能会出现异常,可以通过CSS来修正。
.el-table__body tbody tr:nth-child(2n) td,
.el-table__body tbody tr:nth-child(2n) .cell {
background-color: #f9fafc;
}
八、eltable合并行列浏览器缩放
在浏览器缩放时,eltable的列宽度可能会出现问题,可以通过设置min-width
属性来解决。
.el-table__column {
min-width: 100px;
}
九、eltable合并行 合并单元格
有些时候需要不仅合并行,还需要合并单元格,可以在合并行的基础上使用el-table-column
的colspan
和rowspan
属性来实现。
<el-table-column prop="name" label="姓名" rowspan="2"></el-table-column>
<el-table-column prop="gender" label="性别" rowspan="2"></el-table-column>
<el-table-column prop="birthday" label="出生年月" colspan="2"></el-table-column>
<el-table-column prop="address" label="地址" rowspan="2"></el-table-column>