Kaynağa Gözat

NestedTables

uzairrizwan1 7 ay önce
ebeveyn
işleme
6b407c6abf

+ 5 - 0
myapp/src/App.js

@@ -2,6 +2,9 @@
2 2
 import React from "react";
3 3
 import ChartComponent from "./components/ChartComponent";
4 4
 import FormComponent from "./components/form";
5
+import TableComponent from "./components/table";
6
+import NestedTableComponent from "./components/nestedTable";
7
+
5 8
 
6 9
 
7 10
 function App() {
@@ -10,6 +13,8 @@ function App() {
10 13
       <h1>My Dashboard</h1>
11 14
       <ChartComponent />
12 15
       <FormComponent />
16
+      <TableComponent />
17
+     <NestedTableComponent />
13 18
 
14 19
     </div>
15 20
   );

+ 154 - 0
myapp/src/components/nestedTable.js

@@ -0,0 +1,154 @@
1
+import { DownOutlined } from '@ant-design/icons';
2
+import { Badge, Dropdown, Space, Table } from 'antd';
3
+import React from 'react';
4
+const items = [
5
+  {
6
+    key: '1',
7
+    label: 'Action 1',
8
+  },
9
+  {
10
+    key: '2',
11
+    label: 'Action 2',
12
+  },
13
+];
14
+const NestedTableComponent = () => {
15
+  const expandedRowRender = () => {
16
+    const columns = [
17
+      {
18
+        title: 'Date',
19
+        dataIndex: 'date',
20
+        key: 'date',
21
+      },
22
+      {
23
+        title: 'Name',
24
+        dataIndex: 'name',
25
+        key: 'name',
26
+      },
27
+      {
28
+        title: 'Status',
29
+        key: 'state',
30
+        render: () => (
31
+          <span>
32
+            <Badge status="success" />
33
+            Finished
34
+          </span>
35
+        ),
36
+      },
37
+      {
38
+        title: 'Upgrade Status',
39
+        dataIndex: 'upgradeNum',
40
+        key: 'upgradeNum',
41
+      },
42
+      {
43
+        title: 'Action',
44
+        dataIndex: 'operation',
45
+        key: 'operation',
46
+        render: () => (
47
+          <Space size="middle">
48
+            <a>Pause</a>
49
+            <a>Stop</a>
50
+            <Dropdown
51
+              menu={{
52
+                items,
53
+              }}
54
+            >
55
+              <a>
56
+                More <DownOutlined />
57
+              </a>
58
+            </Dropdown>
59
+          </Space>
60
+        ),
61
+      },
62
+    ];
63
+    const data = [];
64
+    for (let i = 0; i < 3; ++i) {
65
+      data.push({
66
+        key: i.toString(),
67
+        date: '2014-12-24 23:12:00',
68
+        name: 'This is production name',
69
+        upgradeNum: 'Upgraded: 56',
70
+      });
71
+    }
72
+    return <Table columns={columns} dataSource={data} pagination={false} />;
73
+  };
74
+  const columns = [
75
+    {
76
+      title: 'Name',
77
+      dataIndex: 'name',
78
+      key: 'name',
79
+    },
80
+    {
81
+      title: 'Platform',
82
+      dataIndex: 'platform',
83
+      key: 'platform',
84
+    },
85
+    {
86
+      title: 'Version',
87
+      dataIndex: 'version',
88
+      key: 'version',
89
+    },
90
+    {
91
+      title: 'Upgraded',
92
+      dataIndex: 'upgradeNum',
93
+      key: 'upgradeNum',
94
+    },
95
+    {
96
+      title: 'Creator',
97
+      dataIndex: 'creator',
98
+      key: 'creator',
99
+    },
100
+    {
101
+      title: 'Date',
102
+      dataIndex: 'createdAt',
103
+      key: 'createdAt',
104
+    },
105
+    {
106
+      title: 'Action',
107
+      key: 'operation',
108
+      render: () => <a>Publish</a>,
109
+    },
110
+  ];
111
+  const data = [];
112
+  for (let i = 0; i < 3; ++i) {
113
+    data.push({
114
+      key: i.toString(),
115
+      name: 'Screem',
116
+      platform: 'iOS',
117
+      version: '10.3.4.5654',
118
+      upgradeNum: 500,
119
+      creator: 'Jack',
120
+      createdAt: '2014-12-24 23:12:00',
121
+    });
122
+  }
123
+  return (
124
+    <>
125
+      <Table
126
+        columns={columns}
127
+        expandable={{
128
+          expandedRowRender,
129
+          defaultExpandedRowKeys: ['0'],
130
+        }}
131
+        dataSource={data}
132
+      />
133
+      <Table
134
+        columns={columns}
135
+        expandable={{
136
+          expandedRowRender,
137
+          defaultExpandedRowKeys: ['0'],
138
+        }}
139
+        dataSource={data}
140
+        size="middle"
141
+      />
142
+      <Table
143
+        columns={columns}
144
+        expandable={{
145
+          expandedRowRender,
146
+          defaultExpandedRowKeys: ['0'],
147
+        }}
148
+        dataSource={data}
149
+        size="small"
150
+      />
151
+    </>
152
+  );
153
+};
154
+export default NestedTableComponent;

+ 75 - 0
myapp/src/components/table.js

@@ -0,0 +1,75 @@
1
+import { Space, Table, Tag } from 'antd';
2
+import React from 'react';
3
+const columns = [
4
+  {
5
+    title: 'Name',
6
+    dataIndex: 'name',
7
+    key: 'name',
8
+    render: (text) => <a>{text}</a>,
9
+  },
10
+  {
11
+    title: 'Age',
12
+    dataIndex: 'age',
13
+    key: 'age',
14
+  },
15
+  {
16
+    title: 'Address',
17
+    dataIndex: 'address',
18
+    key: 'address',
19
+  },
20
+  {
21
+    title: 'Tags',
22
+    key: 'tags',
23
+    dataIndex: 'tags',
24
+    render: (_, { tags }) => (
25
+      <>
26
+        {tags.map((tag) => {
27
+          let color = tag.length > 5 ? 'geekblue' : 'green';
28
+          if (tag === 'loser') {
29
+            color = 'volcano';
30
+          }
31
+          return (
32
+            <Tag color={color} key={tag}>
33
+              {tag.toUpperCase()}
34
+            </Tag>
35
+          );
36
+        })}
37
+      </>
38
+    ),
39
+  },
40
+  {
41
+    title: 'Action',
42
+    key: 'action',
43
+    render: (_, record) => (
44
+      <Space size="middle">
45
+        <a>Invite {record.name}</a>
46
+        <a>Delete</a>
47
+      </Space>
48
+    ),
49
+  },
50
+];
51
+const data = [
52
+  {
53
+    key: '1',
54
+    name: 'John Brown',
55
+    age: 32,
56
+    address: 'New York No. 1 Lake Park',
57
+    tags: ['nice', 'developer'],
58
+  },
59
+  {
60
+    key: '2',
61
+    name: 'Jim Green',
62
+    age: 42,
63
+    address: 'London No. 1 Lake Park',
64
+    tags: ['loser'],
65
+  },
66
+  {
67
+    key: '3',
68
+    name: 'Joe Black',
69
+    age: 32,
70
+    address: 'Sydney No. 1 Lake Park',
71
+    tags: ['cool', 'teacher'],
72
+  },
73
+];
74
+const TableComponent = () => <Table columns={columns} dataSource={data} />;
75
+export default TableComponent;