-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created a new table component to test react-table viability
- Loading branch information
Tyler Jordan Wright
committed
Oct 2, 2020
1 parent
57fb974
commit 8449bba
Showing
4 changed files
with
117 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Table, TableBody, TableCell, TableHead, TableRow, TableContainer, Paper, TextField } from "@material-ui/core"; | ||
import React from "react"; | ||
import { useTable } from "react-table"; | ||
|
||
export default function ReactTable({ columns, data }) { | ||
// Use the useTable Hook to send the columns and data to build the table | ||
const { | ||
getTableProps, // table props from react-table | ||
getTableBodyProps, // table body props from react-table | ||
headerGroups, // headerGroups, if your table has groupings | ||
rows, // rows for the table based on the data passed | ||
prepareRow // Prepare the row (this function needs to be called for each row before getting the row props) | ||
} = useTable({ | ||
columns, | ||
data | ||
}); | ||
|
||
|
||
|
||
return ( | ||
|
||
<TableContainer component={Paper}> | ||
<Table {...getTableProps} aria-label="simple table"> | ||
<TableHead> | ||
{headerGroups.map(headerGroup => ( | ||
<TableRow {...headerGroup.getHeaderGroupProps()}> | ||
{headerGroup.headers.map(column => ( | ||
<TableCell {...column.getHeaderProps()}>{column.render("Header")}</TableCell> | ||
))} | ||
</TableRow> | ||
))} | ||
|
||
|
||
</TableHead> | ||
<TableBody {...getTableBodyProps()}> | ||
{rows.map((row, i) => { | ||
prepareRow(row); | ||
return ( | ||
<TableRow {...row.getRowProps()}> | ||
{row.cells.map(cell => { | ||
return <TableCell {...cell.getCellProps()}>{cell.render("Cell")}</TableCell>; | ||
})} | ||
</TableRow> | ||
); | ||
})} | ||
</TableBody> | ||
</Table> | ||
</TableContainer> | ||
|
||
); | ||
} |