vue2 Ant-design-vue <a-table 实现行多个单元合并,并内容居中显示

导读:本篇文章讲解 vue2 Ant-design-vue <a-table 实现行多个单元合并,并内容居中显示,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

要求:

最后二行,前4格合并显示:total,与差值

效果:

vue2 Ant-design-vue <a-table 实现行多个单元合并,并内容居中显示

 

实现:

设置某一列的属性时候,增加:customCell在这里style:{}设置内容对齐方式:

重点***:

customCell: (row, index) => {
      return {
        style: {
              ‘font-weight’: ‘bold’,
              ‘background’: ‘rgba(0, 255, 120, 1)’,
              ‘cursor’: ‘pointer’,
              ‘width’: ‘100px’,
              ‘textAlign’:’center’      //对齐方式
    },

columns: [{
          title: '部门',
          dataIndex: 'depId',
          key: 'depId',
    customCell: (row, index) => {
      return {
        style: {
              'font-weight': 'bold',
              'background': 'rgba(0, 255, 120, 1)',
              'cursor': 'pointer',
              'width': '100px',
              'textAlign':'center'
    },
    customRender: (value, row, rowIndex) => { //配置合并设置
        const obj = {
              children: value, //01Np
              attrs: {},
            };
            if (rowIndex === 0) {   // 第一行数据开始,跨行合并的长度为数据data的长度
              // obj.children='01Np'
              obj.attrs.rowSpan = this.dataSource.length - 2; // len表示该数据占几行:u01占4行,合并4行
            } else if (1 <= rowIndex && rowIndex < this.dataSource.length - 2) {    // 从第一行往后的所有行表格均合并,0表格第二行以后的单元格不画
              obj.attrs.rowSpan = 0;
            }
            if (rowIndex >= this.dataSource.length - 2) {
            //最后2格不合并,
              obj.attrs.colSpan = 4
            }
            return obj;
        }
}】

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/101548.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!