_CherryBoom_ 2022-10-12 18:55 采纳率: 50%
浏览 40
已结题

antd 分组了的表格该怎么实现单元格编辑

antd table 表头分组了的表格该怎么实现单元格编辑呀
头大
没个分组的表头下面对应的都是不同的分数 想让这些分数都可以编辑

img

img

img

  • 写回答

1条回答 默认 最新

  • icecreamgaga 2022-10-18 20:49
    关注

    首先,建立一个currentSlots 把你需要修改的列的key放入其中

    reMatchData(collumData,config){//执行这个方法前,this.currentSlots需要置空:this.currentSlots = []; this.rematchData(this.collumData,config)
          collumData.map((item,index)=>{
            if(item.children){
              this.reMatchData(item.children,config)
            }else{
              item.dataIndex = item.key
              item.align = 'center'
              item.color = '#fff'
              item.slots = {customRender: item.key}
              this.currentSlots.push(item.key) //这里是循环collumData,如果要特定slot,需要加判断
              if(config.find(ite=>{return ite.key == item.key})){//这里是特殊的判断,可忽略
                item.width = 150
                item.color = index==1?'#eee':'#ccc'
                if(index == 0){
                  item.fixed = 'left'
                }
              }
            }
          })
        },
    
    

    然后,在table中把这些slots循环加入,editing状态下可修改,非editing状态不修改

    img

    <template v-for="item in currentSlots" #[item]="{record}">
                  <span v-if="!record.editing">{{record[item]}}</span>
                  <span v-if="record.editing"><a-input v-model:value="record[item]">{{record[item]}}</a-input></span>
                </template>
    
    
    

    然后,在customRow的dlclick事件中,给单行数据修改editing
    再然后,在单击事件中,判定如果该行非editing状态,那么,循环table所有行重置为非editing,

    rowClick(record, index) {
          return {
            onclick: (e) => {
              if(!record.editing){
                this.tableData.map(item => {
                  item.editing = false
                })
              }
              if (record.clicking) {
              } else {
                this.tableData.map(item => {
                  item.clicking = false
                })
                record.clicking = true
                this.selectedRowKeys = [index + 1]
              }
            },
            ondblclick: (e) => {
              this.tableData.map(item => {
                item.editing = false
              })
              record.editing = true
            }
          }
        },
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 10月27日
  • 已采纳回答 10月19日
  • 创建了问题 10月12日

悬赏问题

  • ¥15 MYSQL 多表拼接link
  • ¥15 关于某款2.13寸墨水屏的问题
  • ¥15 obsidian的中文层级自动编号
  • ¥15 同一个网口一个电脑连接有网,另一个电脑连接没网
  • ¥15 神经网络模型一直不能上GPU
  • ¥15 pyqt怎么把滑块和输入框相互绑定,求解决!
  • ¥20 wpf datagrid单元闪烁效果失灵
  • ¥15 券商软件上市公司信息获取问题
  • ¥100 ensp启动设备蓝屏,代码clock_watchdog_timeout
  • ¥15 Android studio AVD启动不了