element ui table 表頭跨兩列實現


1、為table添加

:header-cell-style="rowClass"
 
2、通過rowClass 將要跨列的columnIndex 添加屬性 colSpan : 2
 被合並的列隱藏
 
const tableHeaderStyle = {
        background: '#305496',
        color: '#F8F8FF',
        height: '35px',
        padding: '2px',
    }      
    const rowClass = ({ column,rowIndex,columnIndex}) =>{
        if(rowIndex === 0 && columnIndex === 2){
             nextTick(() =>{
            document.getElementsByClassName(column.id)[0].setAttribute('colSpan',2);
            })  //  一定要寫在加載完畢后,nextTick 更新的最晚,才能獲取到dom節點。
        }
        if (rowIndex === 0 && columnIndex === 3){
            return {display:'none'}
        }
    return tableHeaderStyle    
    }
 
感謝:https://blog.csdn.net/weixin_43842567/article/details/115243092


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM