mirror of
https://github.com/gosticks/react-table.git
synced 2025-10-16 11:55:36 +00:00
99 lines
2.0 KiB
JavaScript
Executable File
99 lines
2.0 KiB
JavaScript
Executable File
import React from "react";
|
|
import { render } from "react-dom";
|
|
import { makeData, Logo, Tips } from "./Utils";
|
|
|
|
// Import React Table
|
|
import ReactTable from "react-table";
|
|
import "react-table/react-table.css";
|
|
|
|
const columns = [
|
|
{
|
|
Header: "Name",
|
|
columns: [
|
|
{
|
|
Header: "First Name",
|
|
accessor: "firstName"
|
|
},
|
|
{
|
|
Header: "Last Name",
|
|
id: "lastName",
|
|
accessor: d => d.lastName
|
|
}
|
|
]
|
|
},
|
|
{
|
|
Header: "Info",
|
|
columns: [
|
|
{
|
|
Header: "Age",
|
|
accessor: "age"
|
|
},
|
|
{
|
|
Header: "Status",
|
|
accessor: "status"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
Header: "Stats",
|
|
columns: [
|
|
{
|
|
Header: "Visits",
|
|
accessor: "visits"
|
|
}
|
|
]
|
|
}
|
|
];
|
|
|
|
class App extends React.Component {
|
|
constructor() {
|
|
super();
|
|
this.state = {
|
|
data: makeData()
|
|
};
|
|
}
|
|
render() {
|
|
const { data } = this.state;
|
|
return (
|
|
<div>
|
|
<ReactTable
|
|
data={data}
|
|
columns={columns}
|
|
defaultPageSize={10}
|
|
className="-striped -highlight"
|
|
SubComponent={row => {
|
|
return (
|
|
<div style={{ padding: "20px" }}>
|
|
<em>
|
|
You can put any component you want here, even another React
|
|
Table!
|
|
</em>
|
|
<br />
|
|
<br />
|
|
<ReactTable
|
|
data={data}
|
|
columns={columns}
|
|
defaultPageSize={3}
|
|
showPagination={false}
|
|
SubComponent={row => {
|
|
return (
|
|
<div style={{ padding: "20px" }}>
|
|
Another Sub Component!
|
|
</div>
|
|
);
|
|
}}
|
|
/>
|
|
</div>
|
|
);
|
|
}}
|
|
/>
|
|
<br />
|
|
<Tips />
|
|
<Logo />
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
render(<App />, document.getElementById("root"));
|