Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
import { useNavigate } from 'react-router-dom';
import { PolicyStatusBtn } from "../../../Components/PolicyStatusButton/PolicyStatusBtn";
import { useEffect, useState } from 'react';
import { useGetUserMutation } from "../../../Redux/Apis/userApi";
import { useGetPolicyMutation } from "../../../Redux/Apis/policyApi";
import { useGetPaymentMutation } from "../../../Redux/Apis/paymentApi";
import DropdownArrow from '../../../Assets/Icon/DropdownArrow.svg';
import "./DataTable.css";
export const DataTable = (props) => {
const { columns = [], activeTab } = props;
const [rows, setRows] = useState([]);
const [currentPage, setCurrentPage] = useState(1);
const [pageSize, setPageSize] = useState(10);
const [lastPage, setLastPage] = useState(1);
const [sortOrder, setSortOrder] = useState(null); // State for sorting order
const navigate = useNavigate();
const [getUser] = useGetUserMutation();
const [getPolicy] = useGetPolicyMutation();
const [getPayment] = useGetPaymentMutation();
const fetchData = async () => {
let params = { pageSize, currentPage };
if (sortOrder) params.sortOrder = sortOrder; // Add sorting parameter to API call
switch (activeTab) {
case "Accounts":
const userData = await getUser(params).unwrap();
setRows(userData.users);
setLastPage(Math.ceil(userData.totalRows / pageSize));
break;
case "Policies":
const policyData = await getPolicy(params).unwrap();
setRows(policyData.policy);
setLastPage(Math.ceil(policyData.totalRows / pageSize));
break;
case "Payments":
const paymentData = await getPayment(params).unwrap();
setRows(paymentData.payments);
setLastPage(Math.ceil(paymentData.totalRows / pageSize));
break;
default:
break;
}
};
useEffect(() => {
fetchData();
}, [activeTab, currentPage, pageSize, sortOrder]); // Add sortOrder as a dependency
const handleSortOrderToggle = () => {
// Toggle between "ASC" and "DESC"
setSortOrder(prevOrder => (prevOrder === "ASC" ? "DESC" : "ASC"));
setCurrentPage(1); // Reset to first page when sorting
};
const handlePreviousPage = () => {
if (currentPage > 1) {
setCurrentPage(currentPage - 1);
}
};
const handleNextPage = () => {
if (currentPage < lastPage) {
setCurrentPage(currentPage + 1);
}
};
const handleLastPage = () => setCurrentPage(lastPage);
const handleFirstPage = () => setCurrentPage(1);
const handlePageSizeChange = (event) => setPageSize(event.target.value);
const renderAccountName = (row) => (
<td style={{ width: `${100 / columns.length}%` }} className="custom-td">
<a className="account-name-link">{row.firstName + ' ' + row.lastName}</a>
</td>
);
return (
<>
<div className="data-table-container">
<table className="table table-hover">
<thead className="thead">
<tr className="table-header-row">
{columns.map((column) => (
<th key={column.id} style={{ width: `${100 / columns.length}%` }} className="custom-thead">
<span>
{column.name}
</span>
{column.id === "account_name" && (
<img
src={DropdownArrow}
alt="Dropdown Arrow"
className="dropdown-arrow"
onClick={handleSortOrderToggle} // Toggle sort order on click
style={{ cursor: "pointer" }}
/>
)}
</th>
))}
</tr>
</thead>
<tbody>
{Array.isArray(rows) && rows.map((row) => (
<tr key={row.id}>
{columns.map(column => {
switch (column.id) {
case "account_name":
return renderAccountName(row);
// Add cases for other columns as needed
default:
return <td style={{ width: `${100 / columns.length}%` }} className="custom-td">{row[column.id]}</td>;
}
})}
</tr>
))}
</tbody>
</table>
</div>
<div className="datatable-pagination">
<div className="total-pages">
<p className="pagination-font-style">1-8 of 8</p>
<p className="ml-4 pagination-font-style">
Rows per page
<select value={pageSize} className="page-number" onChange={handlePageSizeChange}>
<option value={10}>10</option>
<option value={20}>20</option>
<option value={30}>30</option>
<option value={40}>40</option>
</select>
</p>
</div>
<div className="pagination-next-previous">
<button onClick={handleFirstPage}>First</button>
<button onClick={handlePreviousPage}>Previous</button>
<span className="active-page">{currentPage}</span>
<button onClick={handleNextPage}>Next</button>
<button onClick={handleLastPage}>Last</button>
</div>
</div>
</>
);
};
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team