由于element ui有一套自己的样式,在实际工作中,我们可能不会照搬,一般会根据需求和设计对element ui进行调整,但是有时候自己写的样式会被element ui影响,不能成功应用。
这次我的工作就是给element表格点击一行给行添加border,按照正常的方式给el-table tr添加border 是行不通的。以下提供两种思路:
一.点击的时候给tr 添加需要的样式(border)
<el-table class="outer-table"
:data="[list]"
:span-method="arraySpanMethod"
row-key="key"
:row-class-name="tableRowClassName"
:cell-class-name="tableCellClassName"
@row-click="rowClick"
default-expand-all
style="width: 100%;background-color: #F3F5F7;" :ref="'table_' + list.id">
</el-table>```
```javascript
tableRowClassName ({row, rowIndex}) {
row.index = rowIndex;
if (this.getIndex === rowIndex ) {
return 'row-style'
}
},
tableCellClassName({row, rowIndex}){
if ((this.getIndex-1) === rowIndex || this.getIndex === rowIndex) {
return 'cell-style'
}
},
rowClick (row) {
this.getIndex=row.index;
},
此处的getIndex需要在data:{}中先定义
style:
/deep/.outer-table.el-table,
/deep/.outer-table .el-table__body-wrapper{
overflow: inherit;
}
/deep/.outer-table .el-table__body{
border-collapse: collapse;
}
/deep/.row-style{
border: 1px solid #409EFF;
box-shadow: inset 0px 0px 6px 0px rgba(64, 158, 255, .6);
}
/deep/.cell-style{
border-bottom: 1px solid #409EFF;
}
因为el-table 有border 参数所以在不添加border参数时,表格只有border-bottom,而border-botttom是在el-table td 上的,所以还得改变el-table td 的样式即给列添加cell-class-name,之所以在开始给tr加border加不上的原因是el-table设置了border-collapse: separate和overflow:hidden
二.就是点击的时候给td加border
第二种方法是给td加上border,即每一列加上border,但是实际情况是点击的时候表格的行只有4个边,如果给td加的话这时候你可以想象,要改变的边的情况比较多,同时要求点击的时候还要有阴影,那么给td加border在实际情况下我是不适用的,所以排除,有兴趣的可以试试。