antd表格合并,设置字体和单独背景色,添加事件

1.html部分

<a-table

        ref="table"

        size="middle"

        bordered

        rowKey="id"

        :scroll="{ x: true }"

        :columns="columns"

        :dataSource="dataSource"

        :pagination="ipagination"

        :loading="loading"

        @change="handleTableChange"

      >

        <template slot="title">

          <div class="title">表格顶部标题</div>

        </template>

      </a-table>

 2.js部分

columns: [

        {

          title: '序号',

          width: '50px',

          align: 'center',

          customRender: (value, record, index) => {

            if (index + 1 !== this.dataSource.length) {

              return `${index + 1}`

            }

            return {

              children: '合计',

              attrs: {

                colSpan: 3   //合并几列,我这里是合并前3列

              },

              style: {

                fontWeight: 'bold'  

              }

            }

          }

        },

        {

          title: '大区',

          align: 'center',

          dataIndex: 'areaName',

          customRender: this.renderContentA

        },

        {

          title: '零售公司',

          align: 'center',

          dataIndex: 'companyName',

          customRender:customRender: (value, row, index) => {

            const obj = {

              children: <a onClick={() => this.handleDetail(row)}>{value}</a>,

              attrs: {}

            }

            if (index + 1 === this.dataSource.length) {

              obj.attrs.colSpan = 0

            }

            return obj

          }

        },

        {

          title: '应观',

          align: 'center',

          dataIndex: 'shouldNum',

          customRender: this.renderContentB

        },

        {

          title: '实观',

          align: 'center',

          dataIndex: 'actualNum',

          customRender: this.renderContentB

        },

        {

          title: '合格',

          align: 'center',

          dataIndex: 'qualifiedNum',

          customRender: this.renderContentB

        },

        {

          title: '覆盖率',

          align: 'center',

          dataIndex: 'coverageRate',

          customRender: this.renderContentC

        },

        {

          title: '合格率',

          align: 'center',

          dataIndex: 'qualifiedRate',

          customRender: this.renderContentC

        },

        {

          title: '平均分',

          align: 'center',

          dataIndex: 'averageScore',

          customRender: this.renderContentC

        }

      ]

 这里我尝试直接attrs添加一个class类名,类名加上了但是给类名写样式不生效,后面尝试用style可以生效

renderContentA(value, row, index) {

      const obj = {

        children: value,

        attrs: {}

      }

      if (index + 1 === this.dataSource.length) {

        obj.attrs.colSpan = 0

      }

      return obj

    },

    renderContentB(value, row, index) {

      const obj = {

        children: value,

        attrs: {}

      }

      if (index + 1 === this.dataSource.length) {

        obj.attrs.colSpan = 1  //合并几列 0 不显示

         obj.attrs.style = 'font-weight: bold' //添加自定义样式

      }

      return obj

    },

    renderContentC(value, row, index) {

      const obj = {

        children:value ,

        attrs: {}

      }

      if (index + 1 === this.dataSource.length) {

        obj.attrs.colSpan = 1 //合并几列 0 不显示

        obj.attrs.style = 'background:#92d050;font-weight: bold' //添加自定义样式

      }

      return obj

    }

3.css部分  给表头添加背景色

/deep/ .ant-table-thead > tr > th {

    color: #111 !important;

    background: #f79646 !important;

    font-weight: bold;

  }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值