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

Fix row expand button added #51

Merged
merged 5 commits into from
Feb 3, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions components/ScholarshipTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const TableHeader = ({ headers }) => (
{header}
</th>
))}
<th className="p-2">Actions</th>
</tr>
</thead>
);
Expand All @@ -23,7 +24,7 @@ const TableCell = ({ children, className = "" }) => (

const ExpandedRow = ({ item, expandedFields }) => (
<tr>
<td colSpan="4" className="p-4 border border-gray-300">
<td colSpan="5" className="p-4 border border-gray-300">
<div className="text-left text-sm sm:text-base">
{expandedFields.map((field, index) => (
<div key={index} className="mb-2">
Expand Down Expand Up @@ -67,17 +68,14 @@ const ScholarshipTable = ({
<tbody>
{filteredData?.length === 0 && (
<tr>
<td colSpan="4" className="p-4 text-center text-gray-700">
<td colSpan="5" className="p-4 text-center text-gray-700">
No scholarships found. Please try again with different filters.
</td>
</tr>
)}
{filteredData?.map((item, index) => (
<React.Fragment key={index}>
<tr
className={`${index % 2 === 0 ? "bg-gray-100" : "bg-white"}`}
onClick={() => toggleRowExpansion(index)}
>
<tr className={`${index % 2 === 0 ? "bg-gray-100" : "bg-white"}`}>
{mainFields.map((field, fieldIndex) => (
<TableCell key={fieldIndex}>{item[field]}</TableCell>
))}
Expand All @@ -87,11 +85,22 @@ const ScholarshipTable = ({
target="_blank"
rel="noopener noreferrer"
className="text-[#B52326] hover:underline"
onClick={(e) => e.stopPropagation()}
>
Apply
</a>
</TableCell>
<TableCell>
<TableCell>
<div className="flex justify-center">
<button
className="px-4 py-2 rounded bg-red-500 text-white hover:bg-red-600 ml-8"
onClick={() => toggleRowExpansion(index)}
>
{expandedRows[index] ? "Show Less" : "Show More"}
</button>
</div>
</TableCell>
</TableCell>
</tr>
{expandedRows[index] && (
<ExpandedRow item={item} expandedFields={expandedFields} />
Expand Down
12 changes: 4 additions & 8 deletions pages/college_predictor.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,25 @@ const CollegePredictor = () => {
// Search Function for fuse
const searchFun = (e) => {
const searchValue = e.target.value.trim();

// If the search box is empty, reset to full data
if (searchValue === "") {
setFilteredData(fullData); // Ensure `fullData` is not empty
setError(null); // Clear any previous error message
return;
}

const result = fuse.search(searchValue);

// Handle no matches found
if (result.length === 0) {
``// Empty the table
``; // Empty the table
setError("No matches found. Please try again."); // Show error
} else {
setFilteredData(result.map((r) => r.item)); // Update filtered data
setError(null); // Clear any error message
}
};




const fetchData = async (query) => {
setIsLoading(true);
Expand Down Expand Up @@ -224,7 +221,6 @@ const CollegePredictor = () => {
</div>
</>
);

};

export default CollegePredictor;