2 个回答

有两种情况:

1: 限制列宽
    出现的问题: 如果数据量少的时候中间会出现空白列。
2: 不限制列宽宽度设置为column
    出现的问题: 如果数据量过大的时候表格的头和表格的数据会有不对齐的情况。
解决:
    采用第一种情况限宽, 可以为table的列最后加一个新空列。
    采用第二种情况不限制列宽, 可以为table设置table-layout: fixed!important属性。(在mac上测试是有效的, win上面有可能会出现意外的情况)。    
新手上路,请多包涵

Antd 表格列固定,实际分成了三块,左右固定的表格覆盖基础表格的固定列信息;所以找到基础表格,将其左右固定列的列宽和分别计算出来,并赋值给左右固定的表格;

mounted(){
  setTimeout(() => {
    const dom1 = document.querySelector(
      ".ant-table .ant-table-scroll .ant-table-fixed"
    );
    const domL = document.querySelector(
      ".ant-table .ant-table-fixed-left .ant-table-fixed"
    );
    const domR = document.querySelector(
      ".ant-table .ant-table-fixed-right .ant-table-fixed"
    );
    const fixedLeftEles = dom1.querySelectorAll(
      "thead th.ant-table-fixedLeft-columns-in-body"
    );
    const selectColumn = dom1.querySelector(
      "thead th.ant-table-selection-column"
    );
    const fixedRightEles = dom1.querySelectorAll(
      "thead th.ant-table-fixedRight-columns-in-body"
    );
    let fixedLeftW = selectColumn ? selectColumn.clientWidth : 0;
    for (let i = 0; i < fixedLeftEles.length; i++) {
      fixedLeftW += fixedLeftEles[i].clientWidth;
    }
    let fixedRightW = 0;
    for (let i = 0; i < fixedRightEles.length; i++) {
      fixedRightW += fixedRightEles[i].clientWidth;
    }
    domL.style.width = fixedLeftW + "px";
    domR.style.width = fixedRightW + "px";
  }, 100);
}
推荐问题