要在您的 上添加页脚ReactTable
,只需Footer
在您的columns
props上定义一个属性。您可以设置一个简单的文本,例如Summary
、JSX 或其他组件。
这是一个像你这样的例子:
import React from "react";
import { render } from "react-dom";
import ReactTable from "react-table";
import "react-table/react-table.css";
const data = [
{
id: 1,
product: "apple",
stock: 1,
price: 123
},
{
id: 2,
product: "pie",
stock: 2,
price: 22
}
];
const App = () => (
<div>
<ReactTable
data={data}
columns={[
{
Header: "Id",
accessor: "id"
},
{
Header: "Product",
accessor: "product",
Footer: "Summary" // Render simple text on the footer
},
{
Header: "Stock",
accessor: "stock"
},
{
Header: "Price",
accessor: "price",
Footer: (
<span>{
// Get the total of the price
data.reduce((total, { price }) => total += price, 0)
}</span>
)
}
]}
defaultPageSize={2}
/>
</div>
);
render(<App />, document.getElementById("root"));
希望这能给你一个想法。