iT邦幫忙

2023 iThome 鐵人賽

DAY 6
0
SideProject30

桌球王系列 第 6

Day 6 - UX

  • 分享至 

  • xImage
  •  

Day 6 - UX

Editable Cells

新增/刪除 選手 (+1 Player)


https://ithelp.ithome.com.tw/upload/images/20230922/20111516ed57B8Pxpo.png

Code

import './App.css';
import { Table,Button,Layout} from 'antd';
import React, { useState } from 'react';

const { Header, Content, Footer } = Layout;

function App() {

  const [count, setCount] = useState(0);
  const data = [
    
  ];   
  const [dataSource, setDataSource] = useState(data)

  const handleAdd = () => {
    const newData = {
      key: count,
      no: count,
      name: `Goish ${count}`,
      action: <a>Delete</a>,
    };
    setDataSource([...dataSource, newData]);
    
    setCount(count+1);
  };

  const handleDelete = (key) => {
    const newData = dataSource.filter((item) => item.key !== key);
    setDataSource(newData);
  };  

  const columns = [
    {
      title: 'No#',
      dataIndex: 'no',
      key: 'no'
      
    },
    {
      title: 'Name',
      dataIndex: 'name',
      key: 'name'
    },
    {
      title: 'Action',
      dataIndex: 'action',
      key: 'action',
      render: (_, record) =>
        dataSource.length >= 1 ? (
          
            <a onClick={() => handleDelete(record.key)}>Delete</a>
          
        ) : null,      
    }
  ];
   
  return (
    <div className="App">

     <Layout>  
      <Header
        style={{
          color: 'white',
          textAlign:'center'
        }}
      >

      桌球出賽名單  

      </Header>      
      <Content className="site-layout" style={{ padding: '0 50px' }}
      >

      <div style={{ padding: 24, height: '100%' }}>  
        <Button type="primary" onClick={handleAdd}>+1 Player</Button>
        <Button style={{marginLeft:6}}>+2 Player</Button>
        
        <br/><br/>
        <Table columns={columns} dataSource={dataSource} />
      </div>  

      </Content>
      <Footer
        style={{
          textAlign: 'center',
          
        }}
      >
        桌球王 ©2023 Created by 阿瑜
      </Footer>      
    </Layout>

    </div>
  );
}

export default App;


上一篇
Day 5 - 排版
下一篇
Day 7 - UX - conti.
系列文
桌球王30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言