Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved table and pagination to MaterialUI. #3

Merged
merged 2 commits into from Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 29 additions & 18 deletions components/BankTable.js
@@ -1,29 +1,40 @@
import React from 'react';
import {
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
Paper,
} from '@mui/material';

const BankTable = ({ banks, currentPage, banksPerPage }) => {
const indexOfLastBank = currentPage * banksPerPage;
const indexOfFirstBank = indexOfLastBank - banksPerPage;
const currentBanks = banks.slice(indexOfFirstBank, indexOfLastBank);

return (
<table style={{ borderCollapse: 'collapse', width: '100%' }}>
<thead>
<tr>
<th style={{ borderBottom: '1px solid', padding: '8px' }}>Bank</th>
<th style={{ borderBottom: '1px solid', padding: '8px' }}>Closing</th>
<th style={{ borderBottom: '1px solid', padding: '8px' }}>Transaction</th>
</tr>
</thead>
<tbody>
{currentBanks.map((bank) => (
<tr key={bank['CERT']} style={{ borderBottom: '1px solid' }}>
<td style={{ padding: '8px' }}>{bank['Bank Name, City, State']}</td>
<td style={{ padding: '8px' }}>{bank['Closing Date']}</td>
<td style={{ padding: '8px' }}>{bank['Acquirer & Transaction']}</td>
</tr>
))}
</tbody>
</table>
<TableContainer component={Paper}>
<Table>
<TableHead>
<TableRow>
<TableCell style={{ width: '20%' }}>Bank</TableCell>
<TableCell style={{ width: '10%' }}>Closing</TableCell>
<TableCell style={{ width: '70%' }}>Transaction</TableCell>
</TableRow>
</TableHead>
<TableBody>
{currentBanks.map((bank) => (
<TableRow key={bank['CERT']}>
<TableCell>{bank['Bank Name, City, State']}</TableCell>
<TableCell>{bank['Closing Date']}</TableCell>
<TableCell>{bank['Acquirer & Transaction']}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
);
};

Expand Down
22 changes: 11 additions & 11 deletions components/Pagination.js
@@ -1,18 +1,18 @@
import React from 'react';
import TablePagination from '@mui/material/TablePagination';

const Pagination = ({ banksPerPage, totalBanks, paginate }) => {
const pageNumbers = [];

for (let i = 1; i <= Math.ceil(totalBanks / banksPerPage); i++) {
pageNumbers.push(i);
}
const Pagination = ({ banksPerPage, totalBanks, handlePageChange, handleRowsPerPageChange }) => {

return (
<nav>
{pageNumbers.map((number) => (
<button key={number.id} onClick={() => paginate(number)}>{number}</button>
))}
</nav>
<TablePagination
component="div"
count={totalBanks}
rowsPerPage={banksPerPage}
page={handlePageChange.page - 1}
onPageChange={(event, newPage) => handlePageChange.handlePageChange(newPage + 1)}
onRowsPerPageChange={(event) => handleRowsPerPageChange(parseInt(event.target.value, 10))}
rowsPerPageOptions={[10, 50, 100]}
/>
);
};

Expand Down