【发布时间】:2021-04-07 01:33:16
【问题描述】:
我想制作一个类似于 gmail 收件箱表格的表格,其中表格列在小屏幕上显示为行。我正在使用 Ant Design 的表格组件,但在文档中找不到如何使其具有响应性。
我想要的大屏幕:
| From | To |
|---|---|
| aaa@example.com | zzz.zzz@example.com |
| ccc@example.com | yyy.yyy@example.com |
我想要的小屏幕:
| From To |
|---|
| aaa@example.com zzz.zzz@example.com |
| ccc@example.com yyy.yyy@example.com |
这是我使用 Ant Design 制作表格的反应代码:
import "./App.css";
import { Table } from "antd";
function App() {
const columns = [
{
title: "From",
dataIndex: "from",
sorter: (a, b) => a.from.length - b.from.length,
sortDirections: ["descend", "ascend"],
},
{
title: "To",
dataIndex: "to",
sorter: (a, b) => a.to - b.to,
sortDirections: ["descend", "ascend"],
},
{
title: "Subject",
dataIndex: "subject",
sorter: (a, b) => a.subject.length - b.subject.length,
sortDirections: ["descend", "ascend"],
},
{
title: "Date",
dataIndex: "date",
sorter: (a, b) => a.date.length - b.date.length,
sortDirections: ["descend", "ascend"],
},
];
const data = [
{
key: "1",
from: "aaa@example.com",
to: "zzz.zzz@example.com",
subject: "[ HR-888 ] Notice of official announcement",
date: "0:20",
},
{
key: "2",
from: "bbb.bbbb@example.com",
to: "yyy.yyy@example.com",
subject: `[web:333] "Web Contact"`,
date: "0:20",
}
];
return (
<div className="App">
<Table columns={columns} dataSource={data} pagination={false} />
</div>
);
}
export default App;
【问题讨论】: