bulk download of csv
This commit is contained in:
@@ -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 <div>Loading...</div>;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Extract unique faculty names
|
||||||
|
// const uniqueTeachers = [...new Set(data.map((row) => row.Name))];
|
||||||
|
|
||||||
|
// return (
|
||||||
|
// <div>
|
||||||
|
// <h1>Faculty Tables with Download Option</h1>
|
||||||
|
// {uniqueTeachers.map((teacher, index) => {
|
||||||
|
// // Filter rows for the current teacher
|
||||||
|
// const teacherData = data.filter((row) => row.Name === teacher);
|
||||||
|
|
||||||
|
// return (
|
||||||
|
// <div key={index} style={{ marginBottom: "20px" }}>
|
||||||
|
// <h2>{teacher}'s Table</h2>
|
||||||
|
// <table border="1" style={{ width: "100%", textAlign: "left", marginBottom: "10px" }}>
|
||||||
|
// <thead>
|
||||||
|
// <tr>
|
||||||
|
// <th>Semester</th>
|
||||||
|
// <th>Course Code</th>
|
||||||
|
// <th>Course Name</th>
|
||||||
|
// <th>Exam Type</th>
|
||||||
|
// <th>Year</th>
|
||||||
|
// <th>Marks</th>
|
||||||
|
// <th>Name</th>
|
||||||
|
// <th>Affiliation/College</th>
|
||||||
|
// <th>Highest Qualification</th>
|
||||||
|
// <th>Career Experience</th>
|
||||||
|
// <th>Oral/Practical</th>
|
||||||
|
// <th>Assessment</th>
|
||||||
|
// <th>Reassessment</th>
|
||||||
|
// <th>Paper Setting</th>
|
||||||
|
// <th>Moderation</th>
|
||||||
|
// <th>PwD Paper Setting</th>
|
||||||
|
// </tr>
|
||||||
|
// </thead>
|
||||||
|
// <tbody>
|
||||||
|
// {teacherData.map((row, idx) => (
|
||||||
|
// <tr key={idx}>
|
||||||
|
// <td>{row.semester}</td>
|
||||||
|
// <td>{row.courseCode}</td>
|
||||||
|
// <td>{row.courseName}</td>
|
||||||
|
// <td>{row.examType}</td>
|
||||||
|
// <td>{row.year}</td>
|
||||||
|
// <td>{row.marks}</td>
|
||||||
|
// <td>{row.Name}</td>
|
||||||
|
// <td>{row.affiliation}</td>
|
||||||
|
// <td>{row.qualification}</td>
|
||||||
|
// <td>{row.experience}</td>
|
||||||
|
// <td>{row.oralPractical}</td>
|
||||||
|
// <td>{row.assessment}</td>
|
||||||
|
// <td>{row.reassessment}</td>
|
||||||
|
// <td>{row.paperSetting}</td>
|
||||||
|
// <td>{row.moderation}</td>
|
||||||
|
// <td>{row.pwdPaperSetting}</td>
|
||||||
|
// </tr>
|
||||||
|
// ))}
|
||||||
|
// </tbody>
|
||||||
|
// </table>
|
||||||
|
// {/* CSV Download Button */}
|
||||||
|
// <CSVLink
|
||||||
|
// data={teacherData}
|
||||||
|
// filename={`${teacher.replace(/\s+/g, "_")}_table.csv`}
|
||||||
|
// className="btn btn-primary"
|
||||||
|
// style={{
|
||||||
|
// padding: "10px 15px",
|
||||||
|
// backgroundColor: "#007bff",
|
||||||
|
// color: "white",
|
||||||
|
// textDecoration: "none",
|
||||||
|
// borderRadius: "5px",
|
||||||
|
// }}
|
||||||
|
// >
|
||||||
|
// Download CSV
|
||||||
|
// </CSVLink>
|
||||||
|
// </div>
|
||||||
|
// );
|
||||||
|
// })}
|
||||||
|
// </div>
|
||||||
|
// );
|
||||||
|
// };
|
||||||
|
|
||||||
|
// export default ConsolidatedTable;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import React, { useState, useEffect, useRef } from "react";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { CSVLink } from "react-csv";
|
import { CSVLink } from "react-csv";
|
||||||
|
|
||||||
const ConsolidatedTable = () => {
|
const ConsolidatedTable = () => {
|
||||||
const [data, setData] = useState([]);
|
const [data, setData] = useState([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
const csvLinksRef = useRef([]); // Ref to store CSV links for bulk download
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
@@ -109,78 +220,135 @@ const ConsolidatedTable = () => {
|
|||||||
// Extract unique faculty names
|
// Extract unique faculty names
|
||||||
const uniqueTeachers = [...new Set(data.map((row) => row.Name))];
|
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 (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h1>Faculty Tables with Download Option</h1>
|
<h1>Faculty Tables with Download Options</h1>
|
||||||
{uniqueTeachers.map((teacher, index) => {
|
|
||||||
// Filter rows for the current teacher
|
|
||||||
const teacherData = data.filter((row) => row.Name === teacher);
|
|
||||||
|
|
||||||
return (
|
{/* Bulk Download Button for Consolidated Data */}
|
||||||
<div key={index} style={{ marginBottom: "20px" }}>
|
<div style={{ marginBottom: "20px" }}>
|
||||||
<h2>{teacher}'s Table</h2>
|
<CSVLink
|
||||||
<table border="1" style={{ width: "100%", textAlign: "left", marginBottom: "10px" }}>
|
data={data}
|
||||||
<thead>
|
filename="Consolidated_Faculty_Table.csv"
|
||||||
<tr>
|
className="btn btn-primary"
|
||||||
<th>Semester</th>
|
style={{
|
||||||
<th>Course Code</th>
|
padding: "10px 15px",
|
||||||
<th>Course Name</th>
|
backgroundColor: "#28a745",
|
||||||
<th>Exam Type</th>
|
color: "white",
|
||||||
<th>Year</th>
|
textDecoration: "none",
|
||||||
<th>Marks</th>
|
borderRadius: "5px",
|
||||||
<th>Name</th>
|
marginRight: "10px",
|
||||||
<th>Affiliation/College</th>
|
}}
|
||||||
<th>Highest Qualification</th>
|
>
|
||||||
<th>Career Experience</th>
|
Download Consolidated CSV
|
||||||
<th>Oral/Practical</th>
|
</CSVLink>
|
||||||
<th>Assessment</th>
|
|
||||||
<th>Reassessment</th>
|
{/* Bulk Download Button for Individual CSV Files */}
|
||||||
<th>Paper Setting</th>
|
<button
|
||||||
<th>Moderation</th>
|
onClick={handleBulkDownload}
|
||||||
<th>PwD Paper Setting</th>
|
className="btn btn-secondary"
|
||||||
</tr>
|
style={{
|
||||||
</thead>
|
padding: "10px 15px",
|
||||||
<tbody>
|
backgroundColor: "#17a2b8",
|
||||||
{teacherData.map((row, idx) => (
|
color: "white",
|
||||||
<tr key={idx}>
|
textDecoration: "none",
|
||||||
<td>{row.semester}</td>
|
borderRadius: "5px",
|
||||||
<td>{row.courseCode}</td>
|
}}
|
||||||
<td>{row.courseName}</td>
|
>
|
||||||
<td>{row.examType}</td>
|
Download All Individual CSVs
|
||||||
<td>{row.year}</td>
|
</button>
|
||||||
<td>{row.marks}</td>
|
</div>
|
||||||
<td>{row.Name}</td>
|
|
||||||
<td>{row.affiliation}</td>
|
{/* Scrollable Content */}
|
||||||
<td>{row.qualification}</td>
|
<div
|
||||||
<td>{row.experience}</td>
|
style={{
|
||||||
<td>{row.oralPractical}</td>
|
maxHeight: "70vh", // Set max height for the scrollable container
|
||||||
<td>{row.assessment}</td>
|
overflowY: "auto", // Enable vertical scrolling
|
||||||
<td>{row.reassessment}</td>
|
border: "1px solid #ccc",
|
||||||
<td>{row.paperSetting}</td>
|
padding: "10px",
|
||||||
<td>{row.moderation}</td>
|
borderRadius: "5px",
|
||||||
<td>{row.pwdPaperSetting}</td>
|
backgroundColor: "#f9f9f9",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{uniqueTeachers.map((teacher, index) => {
|
||||||
|
// Filter rows for the current teacher
|
||||||
|
const teacherData = data.filter((row) => row.Name === teacher);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div key={index} style={{ marginBottom: "20px" }}>
|
||||||
|
<h2>{teacher}'s Table</h2>
|
||||||
|
<table border="1" style={{ width: "100%", textAlign: "left", marginBottom: "10px" }}>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Semester</th>
|
||||||
|
<th>Course Code</th>
|
||||||
|
<th>Course Name</th>
|
||||||
|
<th>Exam Type</th>
|
||||||
|
<th>Year</th>
|
||||||
|
<th>Marks</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Affiliation/College</th>
|
||||||
|
<th>Highest Qualification</th>
|
||||||
|
<th>Career Experience</th>
|
||||||
|
<th>Oral/Practical</th>
|
||||||
|
<th>Assessment</th>
|
||||||
|
<th>Reassessment</th>
|
||||||
|
<th>Paper Setting</th>
|
||||||
|
<th>Moderation</th>
|
||||||
|
<th>PwD Paper Setting</th>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
</thead>
|
||||||
</tbody>
|
<tbody>
|
||||||
</table>
|
{teacherData.map((row, idx) => (
|
||||||
{/* CSV Download Button */}
|
<tr key={idx}>
|
||||||
<CSVLink
|
<td>{row.semester}</td>
|
||||||
data={teacherData}
|
<td>{row.courseCode}</td>
|
||||||
filename={`${teacher.replace(/\s+/g, "_")}_table.csv`}
|
<td>{row.courseName}</td>
|
||||||
className="btn btn-primary"
|
<td>{row.examType}</td>
|
||||||
style={{
|
<td>{row.year}</td>
|
||||||
padding: "10px 15px",
|
<td>{row.marks}</td>
|
||||||
backgroundColor: "#007bff",
|
<td>{row.Name}</td>
|
||||||
color: "white",
|
<td>{row.affiliation}</td>
|
||||||
textDecoration: "none",
|
<td>{row.qualification}</td>
|
||||||
borderRadius: "5px",
|
<td>{row.experience}</td>
|
||||||
}}
|
<td>{row.oralPractical}</td>
|
||||||
>
|
<td>{row.assessment}</td>
|
||||||
Download CSV
|
<td>{row.reassessment}</td>
|
||||||
</CSVLink>
|
<td>{row.paperSetting}</td>
|
||||||
</div>
|
<td>{row.moderation}</td>
|
||||||
);
|
<td>{row.pwdPaperSetting}</td>
|
||||||
})}
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{/* Individual CSV Download Button */}
|
||||||
|
<CSVLink
|
||||||
|
data={teacherData}
|
||||||
|
filename={`${teacher.replace(/\s+/g, "_")}_table.csv`}
|
||||||
|
className="btn btn-primary"
|
||||||
|
style={{
|
||||||
|
padding: "10px 15px",
|
||||||
|
backgroundColor: "#007bff",
|
||||||
|
color: "white",
|
||||||
|
textDecoration: "none",
|
||||||
|
borderRadius: "5px",
|
||||||
|
}}
|
||||||
|
ref={(el) => (csvLinksRef.current[index] = el)} // Store ref for bulk download
|
||||||
|
>
|
||||||
|
Download {teacher}'s CSV
|
||||||
|
</CSVLink>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user