最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue使用Antd中a-table實(shí)現(xiàn)表格數(shù)據(jù)列合并展示示例代碼

 更新時(shí)間:2024年11月09日 12:11:53   作者:JackieDYH  
文章介紹了如何在Vue中使用Ant?Design的a-table組件實(shí)現(xiàn)表格數(shù)據(jù)列合并展示,通過處理函數(shù)對(duì)源碼數(shù)據(jù)進(jìn)行操作,處理相同數(shù)據(jù)時(shí)合并列單元格

原數(shù)據(jù)

根據(jù)需求實(shí)現(xiàn)當(dāng)前兩列數(shù)據(jù)中有相同數(shù)據(jù)時(shí),合并列單元格

實(shí)現(xiàn)

源碼

數(shù)據(jù)

const dataSource = ref([
  {
    id: 1,
    pl: "冰箱",
    zznd: "P1",
    sm: "說(shuō)明說(shuō)明說(shuō)明1",
    dw: "臺(tái)",
    gs: "1",
    dj: "100"
  },
  {
    id: 1,
    pl: "冰箱",
    zznd: "P2",
    sm: "說(shuō)明說(shuō)明說(shuō)明2",
    dw: "臺(tái)",
    gs: "1",
    dj: "100"
  },
  {
    id: 1,
    pl: "冰箱",
    zznd: "P2",
    sm: "說(shuō)明說(shuō)明說(shuō)明3",
    dw: "臺(tái)",
    gs: "1",
    dj: "100"
  },
  {
    id: 1,
    pl: "冰箱",
    zznd: "P3",
    sm: "說(shuō)明說(shuō)明說(shuō)明4",
    dw: "臺(tái)",
    gs: "1",
    dj: "100"
  },
  {
    id: 1,
    pl: "冰箱",
    zznd: "P3",
    sm: "說(shuō)明說(shuō)明說(shuō)明4",
    dw: "臺(tái)",
    gs: "1",
    dj: "100"
  }
])

處理函數(shù)

const calculateRowSpan = (data, index, key) => {
  if (index === 0 || data[index][key] !== data[index - 1][key]) {
    let rowSpan = 1
    for (let i = index + 1; i < data.length; i++) {
      if (data[i][key] === data[index][key]) {
        rowSpan++
      } else {
        break
      }
    }
    return rowSpan
  }
  return 0
}

 全部源碼

<template>
  <a-modal
    title=" "
    :footer="null"
    width="1160px"
    wrap-class-name="price-modal-wrap"
    :open="open"
    @update:open="submit"
    centered
    destroy-on-close>
    <!-- @update:open="(v: boolean) => emit('update:open', v)" -->
    <div class="px-[54px] pb-[30px] pt-3">
      <div class="flex flex-col items-center">
        <img src="@/assets/images/stepTemp/success.svg" alt="" />
        <span class="text-[#000] text-[24px] font-medium mb-[12px]">提交成功</span>
      </div>
      <a-table bordered :loading="loading" :columns="columns" :data-source="dataSource" :pagination="false">
        <template #bodyCell="{ text, column, record, index }">
          <template v-if="!['demandId', 'createTime', 'operator'].includes(String(column.dataIndex))">
            <a-tooltip placement="topLeft" :title="text">
              {{ text }}
            </a-tooltip>
          </template>
        </template>
      </a-table>
      <div class="text-right pt-5">
        <a-button type="primary" class="w-[120px]" @click="submit">確定</a-button>
      </div>
    </div>
  </a-modal>
</template>
<script setup lang="ts">
const props = defineProps<{
  open: boolean
  flag?: string
}>()
const emit = defineEmits(["update:open", "goBack"])
const submit = () => {
  if (props.flag === "table") {
    emit("update:open", false)
    return
  }
  emit("goBack")
}
const dataSource = ref([
  {
    id: 1,
    pl: "冰箱",
    zznd: "P1",
    sm: "說(shuō)明說(shuō)明說(shuō)明1",
    dw: "臺(tái)",
    gs: "1",
    dj: "100"
  },
  {
    id: 1,
    pl: "冰箱",
    zznd: "P2",
    sm: "說(shuō)明說(shuō)明說(shuō)明2",
    dw: "臺(tái)",
    gs: "1",
    dj: "100"
  },
  {
    id: 1,
    pl: "冰箱",
    zznd: "P2",
    sm: "說(shuō)明說(shuō)明說(shuō)明3",
    dw: "臺(tái)",
    gs: "1",
    dj: "100"
  },
  {
    id: 1,
    pl: "冰箱",
    zznd: "P3",
    sm: "說(shuō)明說(shuō)明說(shuō)明4",
    dw: "臺(tái)",
    gs: "1",
    dj: "100"
  },
  {
    id: 1,
    pl: "冰箱",
    zznd: "P3",
    sm: "說(shuō)明說(shuō)明說(shuō)明4",
    dw: "臺(tái)",
    gs: "1",
    dj: "100"
  }
])
const loading = ref(false)
const calculateRowSpan = (data, index, key) => {
  if (index === 0 || data[index][key] !== data[index - 1][key]) {
    let rowSpan = 1
    for (let i = index + 1; i < data.length; i++) {
      if (data[i][key] === data[index][key]) {
        rowSpan++
      } else {
        break
      }
    }
    return rowSpan
  }
  return 0
}
const columns = [
  {
    title: "品類",
    dataIndex: "pl",
    width: 180,
    customCell: (_, index) => {
      const rowSpan = calculateRowSpan(dataSource.value, index, "pl")
      return {
        rowSpan
      }
    }
  },
  {
    title: "制作難度",
    dataIndex: "zznd",
    ellipsis: true,
    width: 180,
    customCell: (_, index) => {
      const rowSpan = calculateRowSpan(dataSource.value, index, "zznd")
      return {
        rowSpan
      }
    }
  },
  {
    title: "說(shuō)明",
    dataIndex: "sm",
    width: 180
  },
  {
    title: "單位(臺(tái)/件)",
    dataIndex: "dw",
    width: 180
  },
  {
    title: "工時(shí)(小時(shí))",
    dataIndex: "gs",
    width: 180
  },
  {
    title: "單價(jià)(元)",
    dataIndex: "dj",
    width: 180
  }
  // {
  //   title: "操作",
  //   dataIndex: "operator",
  //   width: 140
  // }
]
</script>
<style lang="scss">
.price-modal-wrap {
  .ant-modal-content {
    @apply rounded-[20px] overflow-hidden;
  }
  .ant-modal-header {
    @apply rounded-[20px_20px_0_0] py-10 px-[30px] border-none;
  }
  .ant-modal-title {
    @apply text-[20px] font-medium leading-[22px];
  }
  .ant-modal-body {
    padding: 0;
  }
  .ant-modal-close {
    @apply right-[30px] top-[42px];
  }
}
</style>

到此這篇關(guān)于Vue中使用Antd中a-table實(shí)現(xiàn)表格數(shù)據(jù)列合并展示的文章就介紹到這了,更多相關(guān)vue Antd內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue?elementUI?處理文件批量上傳方式

    vue?elementUI?處理文件批量上傳方式

    這篇文章主要介紹了vue?elementUI?處理文件批量上傳方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • 手把手教你如何在vue項(xiàng)目中使用rem布局

    手把手教你如何在vue項(xiàng)目中使用rem布局

    公司內(nèi)部一直有大屏的需求,也一直再做,中途也踩了一些坑,但是沒有認(rèn)真的來(lái)總結(jié)下,下面這篇文章主要給大家介紹了關(guān)于如何在vue項(xiàng)目中使用rem布局的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下
    2023-02-02
  • vue實(shí)現(xiàn)對(duì)highlight-current-row方式整行選中后修改默認(rèn)背景顏色

    vue實(shí)現(xiàn)對(duì)highlight-current-row方式整行選中后修改默認(rèn)背景顏色

    這篇文章主要介紹了vue實(shí)現(xiàn)對(duì)highlight-current-row方式整行選中后修改默認(rèn)背景顏色方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-11-11
  • Ant?Design?Vue?Pagination分頁(yè)組件的封裝與使用

    Ant?Design?Vue?Pagination分頁(yè)組件的封裝與使用

    這篇文章主要介紹了Ant?Design?Vue?Pagination分頁(yè)組件的封裝與使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • vue2?element-ui?el-checkbox視圖不更新問題及解決

    vue2?element-ui?el-checkbox視圖不更新問題及解決

    作者在開發(fā)過程中遇到了視圖不更新的問題,最終通過改變一個(gè)無(wú)關(guān)緊要的響應(yīng)式數(shù)據(jù)來(lái)解決,讓視圖發(fā)生改變
    2024-12-12
  • Vite模塊動(dòng)態(tài)導(dǎo)入之Glob導(dǎo)入實(shí)踐

    Vite模塊動(dòng)態(tài)導(dǎo)入之Glob導(dǎo)入實(shí)踐

    import.meta.glob是Vite提供的強(qiáng)大模塊動(dòng)態(tài)導(dǎo)入功能,用于在構(gòu)建時(shí)批量導(dǎo)入模塊并生成按需加載的代碼,適用于處理大量文件
    2026-01-01
  • vue-cli 3.0 自定義vue.config.js文件,多頁(yè)構(gòu)建的方法

    vue-cli 3.0 自定義vue.config.js文件,多頁(yè)構(gòu)建的方法

    今天小編就為大家分享一篇vue-cli 3.0 自定義vue.config.js文件,多頁(yè)構(gòu)建的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧
    2018-09-09
  • Vue 報(bào)錯(cuò)Error: No PostCSS Config found問題及解決

    Vue 報(bào)錯(cuò)Error: No PostCSS Config foun

    這篇文章主要介紹了Vue 報(bào)錯(cuò)Error: No PostCSS Config found問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-07-07
  • vue2路由方式--嵌套路由實(shí)現(xiàn)方法分析

    vue2路由方式--嵌套路由實(shí)現(xiàn)方法分析

    這篇文章主要介紹了vue2嵌套路由實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了vue2嵌套路由基本實(shí)現(xiàn)方法與操作注意事項(xiàng),需要的朋友可以參考下
    2020-03-03
  • 一文帶你搞懂Vue3中的各種ref的使用

    一文帶你搞懂Vue3中的各種ref的使用

    在?Vue3?中,有許多與響應(yīng)式相關(guān)的函數(shù),例如?toRef、toRefs、isRef、unref?等等,本文將詳細(xì)介紹這些函數(shù)的用法,讓我們?cè)趯?shí)際開發(fā)中知道應(yīng)該使用哪些?API?并能夠熟練地回答面試官的相關(guān)問題
    2023-08-08

最新評(píng)論

措美县| 丹巴县| 丰原市| 定襄县| 黄陵县| 正安县| 公安县| 德化县| 乐都县| 庆安县| 钟祥市| 镇宁| 昌宁县| 黑水县| 河间市| 林周县| 南安市| 莒南县| 新源县| 东乡族自治县| 宁德市| 凤山县| 景泰县| 佛坪县| 渝北区| 门源| 西昌市| 井陉县| 太仆寺旗| 潍坊市| 台前县| 百色市| 上思县| 澄江县| 静海县| 太仆寺旗| 台山市| 五常市| 镇远县| 大洼县| 兰州市|