antd-vue-table 合並相同單元格記錄


var spanArr=[];
var position=0;

//列合並
const renderContent = (value, row, index) => {
  const obj = {
    children: value,
    attrs: {}
  };
  const _row = spanArr[index];
  const _col = _row> 0 ? 1 : 0;
         obj.attrs = {
                rowSpan: _row,
                colSpan: _col
    };

  return obj;
};

//計算合並 const rowspan
= (userData)=>{ spanArr=[]; position=0; userData.forEach((item,index) => { if(index === 0){ spanArr.push(1); position = 0; }else{
//需要合並的地方判斷
if(userData[index].CheckItem === userData[index-1].CheckItem ){ spanArr[position] += 1; spanArr.push(0); }else{ spanArr.push(1); position = index; } } }); } //列名 const columnsScore = [ { title: '編號', dataIndex: 'ScoreId', width: 80, }, { title: '檢查項目', dataIndex: 'CheckItem', width: 100, customRender: renderContent }, { title: '檢查內容', dataIndex: 'CheckContent', width: 130 }, { title: '操作', key: 'action', scopedSlots: { customRender: 'action' } } ]

//請求table數據
      this.$axios({  method: "post", url: "/QuaLity/GetQuality",}).then(res => {
      this.dataSource=res.data.Data;
      rowspan(res.data.Data);
      }).catch(() => { this.$message.error('連接服務器失敗'););
 

最終:

 


免責聲明!

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



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