antd Table 利用自己生成cell结合expandedRowKeys配置,实现任意cell控制展开列

因为项目需要,antd实现一个形如这样的表格








但是奈何翻了好几遍api文档并没有发现这样的东西,只好自己改造了,
首先table是这样的
 <Table 
            columns={this.columns}
            dataSource={tableData} 
            bordered 
            pagination={false}
            size='small'
            expandIconAsCell={false} 
            expandIconColumnIndex={-1}
            expandedRowRender={record=>this.expandedRowTable(record)}
            expandedRowKeys={this.state.expandArray}
          />


实现了隐藏自带按钮、并确定了控制展开行的数组,
接下来就是控制数组了,
先绑定下方法
 onClick={()=>this.expandTable(row)}
  然后 是点击cell的方法
expandTable = row =>{
      const filtered = this.state.expandArray
      const text = this.state.expandBtnText 
      if(this.state.expandArray.includes(row.key)){
        filtered.splice(filtered.findIndex(element => element === row.key),1 );
        this.expandTdNum(parseInt(row.key,10),'reduce') 
        text[parseInt(row.key,10)-1] = '详情'
      }else{
        filtered.push(row.key)
        this.expandTdNum(parseInt(row.key,10),'add') 
        text[parseInt(row.key,10)-1] = '关闭'   
      }
      this.setState({
        expandArray:filtered,
      })
最后控制数组的方法
expandTdNum = (key,operation) =>{
      let temp = 0
      if(operation==='add'){
         temp++
      }else if(operation==='reduce'){
        temp--
      }else{
        return false
      }
      if(key>0 && key<7){
        this.setState({
          firstTdNum:this.state.firstTdNum + temp,
        })
      }else if(key>6 && key<10){
        this.setState({
          middleTdNum:this.state.middleTdNum + temp,
        })
      }else if(key>9 && key<13){
        this.setState({
          lastTdNum:this.state.lastTdNum + temp,
        })
      }
    }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值