合并单元格

17 阅读1分钟
const arraySpanMethod = ({ row, column, rowIndex, columnIndex }) => {
    if (columnIndex === 0) {
      const cellValue = row[column.property];
      if (rowIndex > 0) {
        const previousRow = tableData.value[rowIndex - 1];
        if (previousRow[column.property] === cellValue) {
          return { rowspan: 0, colspan: 1 };
        }
      }
      let rowspan = 1;
      for (let i = rowIndex + 1; i < tableData.value.length; i++) {
        if (tableData.value[i][column.property] === cellValue) {
          rowspan++;
        } else {
          break;
        }
      }
      return { rowspan, colspan: 1 };
    }
  };
 <pure-table
          border
          alignWhole="center"
          showOverflowTooltip
          :loading="loading"
          :data="tableData"
          :span-method="arraySpanMethod"
          :columns="columns"
          height="100%"
        />