简体   繁体   English

获取一定数量的信息到 antd 表

[英]getting certain number of info to antd table

i'm new react hooks developer, i dont know much about classes, started with hooks since everybody suggested, here i have antd table(took it from their page, everything is coded using react classes, i somehow converted it to hooks), here i want to give user possibility to choose how many informtion he/she wants in a page.我是新的 react hooks 开发人员,我对类不太了解,因为每个人都建议,所以从 hooks 开始,这里我有 antd 表(从他们的页面中获取,所有内容都是使用 react 类编码的,我以某种方式将其转换为 hooks),here我想给用户选择他/她想要在一个页面中有多少信息的可能性。 when user clicks that, it should give dropdown list (10 / page, 20 / page, 50 / page, 100 / page ) from dropdown user can choose how many he wants to be visible... so i want that functionality as it is in the picture当用户点击它时,它应该从下拉列表中给出下拉列表(10 / 页,20 / 页,50 / 页,100 / 页)用户可以选择他想要显示的数量......所以我想要那个功能在图片里

在此处输入图像描述 how to have functionality like that with react hooks?如何通过反应钩子拥有这样的功能?

here my code:这是我的代码:

 import React from "react"; import { EventTable } from "./EventTable"; const eventsData = [ { key: "1", title: "John Brown", age: 32, address: "New York No. 1 Lake Park", }, { key: "2", title: "Joe Black", age: 42, address: "London No. 1 Lake Park", }, { key: "3", title: "Jim Green", age: 32, address: "Sidney No. 1 Lake Park", }, { key: "4", title: "Jim Red", age: 32, address: "London No. 2 Lake Park", }, { key: "5", title: "Jim Red", age: 32, address: "London No. 2 Lake Park", }, ]; function App() { return ( <div className="App"> <EventTable eventsData={eventsData} /> </div> ); } export default App;

 import React, { useState, useEffect } from "react"; import { Table } from "antd"; import "antd/dist/antd.css"; const EventTable = ({ eventsData }) => { const allColumns = [ { title: "ID", dataIndex: "key", key: "id", }, { title: "Title", dataIndex: "title", key: "title", }, { title: "Address", dataIndex: "address", key: "address", }, { title: "Age", dataIndex: "age", key: "age", }, ]; const [tableColumns, setTableColumns] = useState(allColumns); return ( <Table dataSource={eventsData} columns={tableColumns} pagination={true} /> ); }; export { EventTable };

You can read the code used for the example, there's a code tab under each component variant, there's also a link to a sandbox, they are really helpful.您可以阅读示例中使用的代码,每个组件变体下都有一个代码选项卡,还有一个沙箱链接,它们真的很有帮助。

I can see that you are sending a boolean to the pagination flag.我可以看到您正在向分页标志发送 boolean 。 What about sending an object like they do?像他们一样发送object怎么样?

const pagination = { 
    defaultPageSize: 3,
    current: 1,
    pageSizeOptions: ['3', '6', '9']
}

And then sending it to the Table .然后将其发送到Table

<Table dataSource={eventsData} columns={tableColumns} pagination={pagination} />

Another detail, you are a React developer , hooks allow us to use Class components features, inside functional components, we can also write our own custom hooks, but they are they are just a feature, you are not a "React Hook dev" .另一个细节,你是一个React 开发者,钩子允许我们使用Class组件特性,在函数式组件内部,我们也可以编写我们自己的自定义钩子,但它们只是一个特性,你不是一个“React Hook 开发者”

React Hooks反应钩子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM