Skip to content

Commit

Permalink
Student details csv export
Browse files Browse the repository at this point in the history
  • Loading branch information
Arif-tekdi-technologies committed Mar 15, 2024
1 parent 7958452 commit 745dea8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/admin/src/assets/images/FinalStudent.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
name,email,mobile,gender,dateOfBirth,board,password,status,className,religion,school_udise,caste,annual_income,mother_education,father_education,mother_occupation,father_occupation,No_of_siblings
Dane Oliver,,8100091086,Female,2005-12-12,Maharashtra,12345,TRUE,Class 10,Hindu,12345678,test,100000,test,test,test,test,5
name,username,email,mobile,gender,dateOfBirth,board,password,status,className,religion,school_udise,caste,annual_income,mother_education,father_education,mother_occupation,father_occupation,No_of_siblings
Test,,,9999999999,Female ,1990-01-03,West Bengal,NA ,TRUE,Class 6,Hindu,12345678,General,668,,,,,
Testing,,,9999999999,Female ,1990-01-03,West Bengal,NA ,TRUE,Class 6,Muslim,12345678,General,668,,,,,
Tester,,,9999999999,Female ,1990-01-03,West Bengal,NA ,TRUE,Class 6,Christian,12345678,General,668,,,,,
54 changes: 53 additions & 1 deletion packages/admin/src/components/StudentListView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,38 @@ function StudentListView() {
}
};

const onBtnExportDetails = async () => {
let username = window.prompt(`Enter a username for student details`);
username = username.trim();
if (username == null || username == "") {
alert("Please enter a valid username");
} else {
console.log(username);

// Find the row corresponding to the entered username in the rowData array
const student = rowData.find((student) => student.username === username);

if (student) {
// Convert student details to CSV format
const csvData = Papa.unparse([student]);

// Create a Blob containing the CSV data
const blob = new Blob([csvData], { type: "text/csv;charset=utf-8;" });

// Create a download link and trigger the download
const link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = `${username}_details.csv`;
link.style.display = "none";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
} else {
alert("Student not found in the table");
}
}
};

useEffect(() => {
const token = sessionStorage.getItem("token");
setToken(token);
Expand All @@ -242,7 +274,7 @@ function StudentListView() {
};

const requestData = {
limit: "",
limit: "25",
page: 1,
filters: {},
};
Expand Down Expand Up @@ -344,6 +376,26 @@ function StudentListView() {
/>
<H4 style={{ color: "white" }}> Download username & password </H4>
</button>
<button
onClick={onBtnExportDetails}
style={{
background: "#41C88E",
border: "none",
borderRadius: "5px",
marginLeft: "10px",
display: "flex",
cursor: "pointer",
alignItems: "center",
}}
>
<FileDownloadOutlinedIcon
style={{
color: "white",
fontSize: "largest",
}}
/>
<H4 style={{ color: "white" }}> Download student details </H4>
</button>
</div>
<div
style={{
Expand Down

0 comments on commit 745dea8

Please sign in to comment.