From d96d27154bd274c90007040e1312dee19ec0007f Mon Sep 17 00:00:00 2001
From: Harikrishnan Gopal <118685394+hk151109@users.noreply.github.com>
Date: Thu, 23 Jan 2025 20:39:19 +0530
Subject: [PATCH] bulk download of csv
---
client/src/Pages/ConsolidatedTable.jsx | 306 +++++++++++++++++++------
1 file changed, 237 insertions(+), 69 deletions(-)
diff --git a/client/src/Pages/ConsolidatedTable.jsx b/client/src/Pages/ConsolidatedTable.jsx
index f18505c..d38dea5 100644
--- a/client/src/Pages/ConsolidatedTable.jsx
+++ b/client/src/Pages/ConsolidatedTable.jsx
@@ -79,13 +79,124 @@
-import React, { useState, useEffect } from "react";
+// import React, { useState, useEffect } from "react";
+// import axios from "axios";
+// import { CSVLink } from "react-csv";
+
+// const ConsolidatedTable = () => {
+// const [data, setData] = useState([]);
+// const [loading, setLoading] = useState(true);
+
+// useEffect(() => {
+// const fetchData = async () => {
+// try {
+// const response = await axios.get("http://localhost:8080/api/table/consolidated-table");
+// setData(response.data);
+// setLoading(false);
+// } catch (error) {
+// console.error("Error fetching table data:", error);
+// setLoading(false);
+// }
+// };
+
+// fetchData();
+// }, []);
+
+// if (loading) {
+// return
Loading...
;
+// }
+
+// // Extract unique faculty names
+// const uniqueTeachers = [...new Set(data.map((row) => row.Name))];
+
+// return (
+//
+//
Faculty Tables with Download Option
+// {uniqueTeachers.map((teacher, index) => {
+// // Filter rows for the current teacher
+// const teacherData = data.filter((row) => row.Name === teacher);
+
+// return (
+//
+//
{teacher}'s Table
+//
+//
+//
+// | Semester |
+// Course Code |
+// Course Name |
+// Exam Type |
+// Year |
+// Marks |
+// Name |
+// Affiliation/College |
+// Highest Qualification |
+// Career Experience |
+// Oral/Practical |
+// Assessment |
+// Reassessment |
+// Paper Setting |
+// Moderation |
+// PwD Paper Setting |
+//
+//
+//
+// {teacherData.map((row, idx) => (
+//
+// | {row.semester} |
+// {row.courseCode} |
+// {row.courseName} |
+// {row.examType} |
+// {row.year} |
+// {row.marks} |
+// {row.Name} |
+// {row.affiliation} |
+// {row.qualification} |
+// {row.experience} |
+// {row.oralPractical} |
+// {row.assessment} |
+// {row.reassessment} |
+// {row.paperSetting} |
+// {row.moderation} |
+// {row.pwdPaperSetting} |
+//
+// ))}
+//
+//
+// {/* CSV Download Button */}
+//
+// Download CSV
+//
+//
+// );
+// })}
+//
+// );
+// };
+
+// export default ConsolidatedTable;
+
+
+
+import React, { useState, useEffect, useRef } from "react";
import axios from "axios";
import { CSVLink } from "react-csv";
const ConsolidatedTable = () => {
const [data, setData] = useState([]);
const [loading, setLoading] = useState(true);
+ const csvLinksRef = useRef([]); // Ref to store CSV links for bulk download
useEffect(() => {
const fetchData = async () => {
@@ -109,78 +220,135 @@ const ConsolidatedTable = () => {
// Extract unique faculty names
const uniqueTeachers = [...new Set(data.map((row) => row.Name))];
+ const handleBulkDownload = () => {
+ // Trigger all individual downloads programmatically
+ csvLinksRef.current.forEach((csvLink) => {
+ if (csvLink) {
+ csvLink.link.click();
+ }
+ });
+ };
+
return (
-
Faculty Tables with Download Option
- {uniqueTeachers.map((teacher, index) => {
- // Filter rows for the current teacher
- const teacherData = data.filter((row) => row.Name === teacher);
+
Faculty Tables with Download Options
- return (
-
-
{teacher}'s Table
-
-
-
- | Semester |
- Course Code |
- Course Name |
- Exam Type |
- Year |
- Marks |
- Name |
- Affiliation/College |
- Highest Qualification |
- Career Experience |
- Oral/Practical |
- Assessment |
- Reassessment |
- Paper Setting |
- Moderation |
- PwD Paper Setting |
-
-
-
- {teacherData.map((row, idx) => (
-
- | {row.semester} |
- {row.courseCode} |
- {row.courseName} |
- {row.examType} |
- {row.year} |
- {row.marks} |
- {row.Name} |
- {row.affiliation} |
- {row.qualification} |
- {row.experience} |
- {row.oralPractical} |
- {row.assessment} |
- {row.reassessment} |
- {row.paperSetting} |
- {row.moderation} |
- {row.pwdPaperSetting} |
+ {/* Bulk Download Button for Consolidated Data */}
+
+
+ Download Consolidated CSV
+
+
+ {/* Bulk Download Button for Individual CSV Files */}
+
+
+
+ {/* Scrollable Content */}
+
+ {uniqueTeachers.map((teacher, index) => {
+ // Filter rows for the current teacher
+ const teacherData = data.filter((row) => row.Name === teacher);
+
+ return (
+
+
{teacher}'s Table
+
+
+
+ | Semester |
+ Course Code |
+ Course Name |
+ Exam Type |
+ Year |
+ Marks |
+ Name |
+ Affiliation/College |
+ Highest Qualification |
+ Career Experience |
+ Oral/Practical |
+ Assessment |
+ Reassessment |
+ Paper Setting |
+ Moderation |
+ PwD Paper Setting |
- ))}
-
-
- {/* CSV Download Button */}
-
- Download CSV
-
-
- );
- })}
+
+
+ {teacherData.map((row, idx) => (
+
+ | {row.semester} |
+ {row.courseCode} |
+ {row.courseName} |
+ {row.examType} |
+ {row.year} |
+ {row.marks} |
+ {row.Name} |
+ {row.affiliation} |
+ {row.qualification} |
+ {row.experience} |
+ {row.oralPractical} |
+ {row.assessment} |
+ {row.reassessment} |
+ {row.paperSetting} |
+ {row.moderation} |
+ {row.pwdPaperSetting} |
+
+ ))}
+
+
+ {/* Individual CSV Download Button */}
+
(csvLinksRef.current[index] = el)} // Store ref for bulk download
+ >
+ Download {teacher}'s CSV
+
+
+ );
+ })}
+
);
};