pramod_Task#68_projectListInAscending #20
@ -53,8 +53,15 @@ const EmployeeList = () =>
|
|||||||
setCurrentPage(1);
|
setCurrentPage(1);
|
||||||
|
|
||||||
if (!loading && Array.isArray(employees)) {
|
if (!loading && Array.isArray(employees)) {
|
||||||
setEmployeeList(employees);
|
// Sort by full name (firstName + lastName)
|
||||||
setFilteredData(employees);
|
const sorted = [...employees].sort((a, b) => {
|
||||||
|
const nameA = `${a.firstName || ""}${a.lastName || ""}`.toLowerCase();
|
||||||
|
const nameB = `${b.firstName || ""}${b.lastName || ""}`.toLowerCase();
|
||||||
|
return nameA.localeCompare(nameB);
|
||||||
|
});
|
||||||
|
|
||||||
|
setEmployeeList(sorted);
|
||||||
|
setFilteredData(sorted);
|
||||||
}
|
}
|
||||||
}, [loading, employees, selectedProject]);
|
}, [loading, employees, selectedProject]);
|
||||||
|
|
||||||
@ -343,7 +350,6 @@ const EmployeeList = () =>
|
|||||||
{currentItems &&
|
{currentItems &&
|
||||||
!loading &&
|
!loading &&
|
||||||
currentItems
|
currentItems
|
||||||
.sort((a, b) => b.id - a.id)
|
|
||||||
.map((item) => (
|
.map((item) => (
|
||||||
<tr className="odd" key={item.id}>
|
<tr className="odd" key={item.id}>
|
||||||
<td className="sorting_1" colSpan={2}>
|
<td className="sorting_1" colSpan={2}>
|
||||||
|
@ -33,7 +33,29 @@ const ProjectList = () =>
|
|||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setProjectList( projects )
|
if (!loading && Array.isArray(projects)) {
|
||||||
|
// Step 1: Group projects by statusId
|
||||||
|
const grouped = {};
|
||||||
|
|
||||||
|
projects.forEach((project) => {
|
||||||
|
const statusId = project.projectStatusId;
|
||||||
|
if (!grouped[statusId]) {
|
||||||
|
grouped[statusId] = [];
|
||||||
|
}
|
||||||
|
grouped[statusId].push(project);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Step 2: Sort each group by name
|
||||||
|
const sortedGrouped = Object.keys(grouped)
|
||||||
|
.sort() // sort group keys (status IDs)
|
||||||
|
.flatMap((statusId) =>
|
||||||
|
grouped[statusId].sort((a, b) =>
|
||||||
|
a.name.toLowerCase().localeCompare(b.name.toLowerCase())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
setProjectList(sortedGrouped); // final sorted flat list
|
||||||
|
}
|
||||||
|
|
||||||
}, [ projects, loginUser?.projects, loading ] );
|
}, [ projects, loginUser?.projects, loading ] );
|
||||||
|
|
||||||
@ -85,20 +107,8 @@ const ProjectList = () =>
|
|||||||
? Math.ceil(projectList.length / itemsPerPage)
|
? Math.ceil(projectList.length / itemsPerPage)
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
const statusMap = {
|
|
||||||
1: { label: 'active', priority: 1 },
|
|
||||||
2: { label: 'hold', priority: 2 },
|
|
||||||
3: { label: 'inactive', priority: 3 },
|
|
||||||
4: { label: 'complete', priority: 4 }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const sortedProjects = [...currentItems].sort((a, b) => {
|
|
||||||
const aPriority = statusMap[+a.projectStatusId]?.priority ?? 99;
|
|
||||||
const bPriority = statusMap[+b.projectStatusId]?.priority ?? 99;
|
|
||||||
return aPriority - bPriority;
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
@ -167,7 +177,7 @@ const ProjectList = () =>
|
|||||||
|
|
||||||
|
|
||||||
{currentItems &&
|
{currentItems &&
|
||||||
sortedProjects.map((item) => (
|
currentItems.map((item) => (
|
||||||
<ProjectCard projectData={item} key={item.id}></ProjectCard>
|
<ProjectCard projectData={item} key={item.id}></ProjectCard>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user