1.项目中使用到element时就会用到el-table,当table的项太多时就会使用到表格某一项的固定,如下,操作项和日期被设置了fixed属性…
2.table中用到列定制时,或者表格的列根据某种条件渲染时,会出现列渲染错乱的情况,如性格列渲染到年龄一列
<el-table
:data="tableData"
border
style="width: 100%">
<el-table-column
fixed
prop="date"
label="日期"
width="150">
</el-table-column>
<el-table-column
fixed="right"
label="操作"
width="100">
<template slot-scope="scope">
<el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
<el-button type="text" size="small">编辑</el-button>
</template>
</el-table-column>
</el-table>
一旦设置fixed属性,对表格进行编辑,新增等操作时,表格被设置fixed的项下面就会出现伪横线,如下
1.在不带scoped的公共页面样式部门添加
.el-table__fixed-right{
height: 100% !important;
}
我加了这个属性之后,操作栏的伪横线不见了,但是序号栏的还在,我就又加了第二个属性
2.因为我是编辑了表格加载之后就会出现这个伪横线,所以使用 el-table的doLayout方法进行重新布局,代码如下
<el-table ref="multipleTable" :data="tableData">
...
</el-table>
getTableList() {
let targetForm = Object.assign(this.searchForm, this.reqForm, {"conferenceId": this.conferenceId})
conferenceAuditApi.getPeportManList(targetForm).then(res => {
this.tableData = res.data.data
// console.log(this.tableData);
this.total = res.data.total
this.$nextTick(() => {
this.$refs.multipleTable.doLayout()
})
}).finally(() => {
this.tableLoading = false;
});
},
以上俩方案,解决了我的表格分裂的问题,
这种导致是表格的列是根据后期查询接口判断该条是否展示,也可以根据列定制,判断该列是否展示,如果不更新这个列key的话,显示/隐藏列的时候,部分DOM不会重新渲染,导致table变化时候内容错乱。这个问题也可能是由于判断条件是v-if,换成v-show应该不会出现此类问题,
v-show是不管初始条件是什么,元素总是会被渲染。
v-if 切换有一个局部编译/卸载的过程
<el-table :data="tableData" border stripe ref="multipleTable" v-loading='tableLoading'>
<el-table-column type="index" label="序号" width="70">el-table-column>
<el-table-column v-if="colDisplay('username')" prop="username" label="姓名" min-width="140" key="username">el-table-column>
<el-table-column v-if="colDisplay('sex')" prop="sex" label="性别" min-width="60" key="sex">
<template slot-scope="{row}">{{ $dict.getLabel('sys_sex', row.sex) }}template>
el-table-column>
<el-table-column v-if="colDisplay('orgName')" prop="orgName" label="单位" min-width="140" key="orgName">el-table-column>
<el-table-column v-if="colDisplay('post')" prop="post" label="部门及职务" min-width="140" key="post">el-table-column>
<el-table-column v-if="colDisplay('rank')" prop="rank" label="职级" min-width="140" key="rank">
<template slot-scope="{row}">{{ $dict.getLabel('participate_rank', row.rank) }}template>
el-table-column>
<el-table-column v-if="colDisplay('nation')" prop="nation" label="民族" min-width="140" key="nation">el-table-column>
<el-table-column v-if="colDisplay('officePhone')" prop="officePhone" label="本人办公电话" min-width="140" key="officePhone">el-table-column>
<el-table-column v-if="colDisplay('phone')" prop="phone" label="本人手机" min-width="140" key="phone">el-table-column>
<el-table-column v-if="colDisplay('awardName')" prop="awardName" label="奖项名称" min-width="140" key="awardName">el-table-column>
<el-table-column v-if="colDisplay('remarks')" prop="remarks" label="备注信息" min-width="140" key="remarks">el-table-column>
<el-table-column v-if="colDisplay('isReceive')" prop="isReceive" label="是否接站" min-width="140" key="isReceive">
<template slot-scope="{row}">{{ $dict.getLabel('sf_yes_no_none', row.isReceive) }}template>
el-table-column>
<el-table-column v-if="colDisplay('arrivalDate')" prop="arrivalDate" label="到达时间" min-width="140" key="arrivalDate">el-table-column>
<el-table-column v-if="colDisplay('arrivalSite')" prop="arrivalSite" label="到达站点" min-width="140" key="arrivalSite">el-table-column>
<el-table-column v-if="colDisplay('arrivalFlight')" prop="arrivalFlight" label="到达航班/车次" min-width="140" key="arrivalFlight">el-table-column>
<el-table-column v-if="colDisplay('isSend')" prop="isSend" label="是否送站" min-width="140" key="isSend">
<template slot-scope="{row}">{{ $dict.getLabel('sf_yes_no_none', row.isSend) }}template>
el-table-column>
<el-table-column v-if="colDisplay('leaveDate')" prop="leaveDate" label="出发时间" min-width="140" key="leaveDate">el-table-column>
<el-table-column v-if="colDisplay('leaveFlight')" prop="leaveFlight" label="出发航班/车次" min-width="140" key="leaveFlight">el-table-column>
<el-table-column v-if="colDisplay('leaveSite')" prop="leaveSite" label="出发站点" min-width="140" key="leaveSite">el-table-column>
<el-table-column prop="auditStatus" label="状态" fixed="right" key="auditStatus">
<template slot-scope="{row}">{{auditStatusList[row.auditStatus]}}template>
el-table-column>
<el-table-column label="操作" width="200" fixed="right">
<template slot-scope="{row,$index}">
<span v-if="(row.auditStatus!=='1')&&(row.auditStatus!=='5')">
<el-link style="color: #c7000b;" :underline="false" type="primary" @click="edit(row)"><i class="el-icon-edit" style="padding-right: 8px">i>编辑el-link>
<el-divider direction="vertical">el-divider>
span>
<span v-if="(row.auditStatus!=='1')&&(row.auditStatus!=='5')">
<el-link style="color: #c7000b;" :underline="false" type="primary" @click="del(row,$index)"><i class="el-icon-delete" style="padding-right: 8px">i>删除el-link>
span>
template>
el-table-column>
el-table>
在每一个el-table-column 上增加key,给每一个一个唯一标识 ,key可以是每一列的值也可以是随机数 :key=“Math.random()”
<el-table :data="tableData" stripe border v-loading='tableLoading'>
<el-table-column type="index" width="70" label="序号"></el-table-column>
<el-table-column label="操作" :width="orgId=='ZY001'?600:300" fixed="right" >
<template slot-scope="{row,$index}">
<span>
<el-link style="color: #c7000b;" :underline="false" type="primary" @click="viewConference(row, $index)" title="查看会议"><i class="el-icon-view"></i>查看会议</el-link>
</span>
</span>
</template>
</el-table-column>
</el-table>
这个问题是由于表格的操作项设置fixed="right"后,导致右侧操作项的层级比滚动条高,所以触发不了滚动,解决办法就是提高滚动条的层级
在app.vue下面设置如下css
.el-table--scrollable-x .el-table__body-wrapper {
z-index : 1;
}
:cell-class-name="tableCellClassName" // 设置项
:row-class-name="tablerowrule" //设置行