Add export functionality for employee data in various formats

This commit is contained in:
Vaibhav Surve 2025-04-18 12:13:47 +05:30
parent 95ddc91f5f
commit f6b5b78d2d

View File

@ -1,4 +1,4 @@
import React, { useState, useEffect } from "react";
import React, { useState, useEffect,useRef } from "react";
import moment from "moment";
import { Link, NavLink, useNavigate } from "react-router-dom";
import Avatar from "../../components/common/Avatar";
@ -11,6 +11,7 @@ import { hasUserPermission } from "../../utils/authUtils";
import { MANAGE_EMPLOYEES } from "../../utils/constants";
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
import SuspendEmp from "../../components/Employee/SuspendEmp";
import {exportToCSV,exportToExcel,printTable,exportToPDF} from "../../utils/tableExportUtils";
const EmployeeList = () => {
const { profile: loginUser } = useProfile();
@ -101,7 +102,29 @@ const EmployeeList = () => {
openModal();
}
}, [modelConfig, isCreateModalOpen]);
const tableRef = useRef(null);
const handleExport = (type) => {
if (!currentItems || currentItems.length === 0) return;
switch (type) {
case "csv":
exportToCSV(currentItems, "employees");
break;
case "excel":
exportToExcel(currentItems, "employees");
break;
case "pdf":
exportToPDF(currentItems, "employees"); // Pass the employeeList directly
break;
case "print":
printTable(tableRef.current);
break;
default:
break;
}
};
return (
<>
{isCreateModalOpen && (
@ -198,13 +221,23 @@ const EmployeeList = () => {
</button>
<ul className="dropdown-menu">
<li>
<a
aria-label="dropdown item action"
className="dropdown-item"
href="#"
>
{/* <i className="bx bx-printer me-1"></i> */}
Coming Soon
<a className="dropdown-item" href="#" onClick={() => handleExport("print")}>
<i className="bx bx-printer me-1"></i> Print
</a>
</li>
<li>
<a className="dropdown-item" href="#" onClick={() => handleExport("csv")}>
<i className="bx bx-file me-1"></i> CSV
</a>
</li>
<li>
<a className="dropdown-item" href="#" onClick={() => handleExport("excel")}>
<i className="bx bxs-file-export me-1"></i> Excel
</a>
</li>
<li>
<a className="dropdown-item" href="#" onClick={() => handleExport("pdf")}>
<i className="bx bxs-file-pdf me-1"></i> PDF
</a>
</li>
</ul>
@ -237,6 +270,7 @@ const EmployeeList = () => {
id="DataTables_Table_0"
aria-describedby="DataTables_Table_0_info"
style={{ width: "100%" }}
ref={tableRef}
>
<thead>
<tr>