table单元格合并,行高修改

Ant Design Vue table组件单元格合并、行高修改


一、Ant Design Vue table组件单元格合并、行高修改

直接上代码

<template>
  <a-modal :visible="props.visible" width="100%" title="详情" @cancel="closeModal" @ok="closeModal" centered>

    <a-table :columns="columns" :data-source="tableData" :bordered="true" :pagination="false" :scroll="{ y: scrollY }"></a-table>
  </a-modal>
</template>

<script lang="ts" name="spotTotalDown" setup>
import type { TableColumnsType } from 'ant-design-vue';
import {onBeforeMount, ref, watch} from 'vue';
import { list } from "./projectContact.api";
const emit = defineEmits(['closeModal'])
const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  },
})


const columns: TableColumnsType = [

  {
    title: '序号',
    customRender: ({ index }: { index: number }) => {
      return `${index + 1}`
    },
    width: 100
  },

  {
    title:'业务部门',
    width:200,
    dataIndex: 'BUSINESS_DEPARTMENT',
    //单元格合并
    customCell: (record, index) => {
      let arr = tableData.value.filter((res) => {
        //这里BUSINESS_DEPARTMENT 是我需要判断的字段名(相同就合并)
        return res.BUSINESS_DEPARTMENT == record.BUSINESS_DEPARTMENT;
      });
      if (index == 0 || tableData.value[index - 1].BUSINESS_DEPARTMENT != record.BUSINESS_DEPARTMENT) {
        return { rowSpan: arr.length };
      } else {
        return { rowSpan: 0 };
      }
    }
  },
  {
    title:'系统名称',
    width:250,
    dataIndex: 'XT_NAME'
  },
  {
    title:'业务DRI',
    width:250,
    dataIndex: 'YW_DRI'
  },
  {
    title:'开发DRI',
    width:300,
    dataIndex: 'KF_DRI'
  },
  // {
  //   title:'开发邮箱',
  //   width:300,
  //   dataIndex: 'KF_EMAIL'
  // },
  {
    title:'紧急联系人',
    // width:400,
    dataIndex: 'EMERGENCY_CONTACT'
  },
];

const tableData = ref([])
const closeModal = () => {
  emit('closeModal')
}
const scrollY = ref<boolean | number>(false)

const spotTotalview = async () => {
  const res = await list();
  tableData.value = res.result
};


onBeforeMount(()=>{
  spotTotalview()
  if (window.innerWidth < 1400) {
    scrollY.value = 460
  } else {
    scrollY.value = false
  }

  window.addEventListener('resize', () => {
    if (window.innerWidth < 1400) {
      scrollY.value = 460
    } else {
      scrollY.value = false
    }
  })
})


</script>

<style scoped>
:deep(.ant-table-thead > tr > th) {
  border-right: 1px solid #000000 !important;
  border-bottom: 1px solid #000000 !important;
  border-top: 1px solid #000000 !important;
  padding: 8px 0 !important;
  //b表头加粗
  font-weight: bolder !important;
}


:deep(.ant-table-tbody > tr > td) {
  border-bottom: 1px solid #000000 !important;
  border-right: 1px solid #000000 !important;
  //行高
  padding: 0 !important;
}

</style>

二、效果

在这里插入图片描述


总结

记录、备忘

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值