antd pro table 单元格 loading

前言:在protable单元格中增加loading,还真没思路,看render()方法的四个参数,感觉都用不上。

后来在朋友的帮助下用如下方法解决。

 

复制代码
import React, { useState } from 'react';
import { Space, Spin, Table } from 'antd';
 
// 发空投loading
const [loading, setLoading] = useState(false)
const [currId, setCurrId] = useState(0)


const columns = [
  {
      title: '状态',
      width: '100px',
      key: 'status',
      dataIndex: 'status',
      ellipsis: true,
      hideInSearch: true, // 在查询表单中不展示此项
      render: (text, record, _, action)=> {
        const statusArr = ['', '未发放', '待确认', '发放成', '发放失败', '无效']
        return (loading && record.id === currId) ? <Spin indicator={<LoadingOutlined style={{ fontSize: 24 }} spin />} /> : statusArr[record.status]
  },
  {
    title: 'Age',
    dataIndex: 'age',
    key: 'age',
  },
  // ... 其他列
];
 


// 发空投
const onSendClick = async(item: any) => {
  setCurrId(item.id)
  setLoading(true)
  异步
  setLoading(false)
},
 

const App = () => {
  return <Table columns={columns} dataSource={data} />;
};
 
export default App;
复制代码

 

posted @   走走停停走走  Views(239)  Comments(0Edit  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
历史上的今天:
2014-04-17 用到的知识点
点击右上角即可分享
微信分享提示