pramod_Task#68_projectListInAscending #20
@ -53,8 +53,15 @@ const EmployeeList = () =>
|
||||
setCurrentPage(1);
|
||||
|
||||
if (!loading && Array.isArray(employees)) {
|
||||
setEmployeeList(employees);
|
||||
setFilteredData(employees);
|
||||
// Sort by full name (firstName + lastName)
|
||||
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]);
|
||||
|
||||
@ -343,7 +350,6 @@ const EmployeeList = () =>
|
||||
{currentItems &&
|
||||
!loading &&
|
||||
currentItems
|
||||
.sort((a, b) => b.id - a.id)
|
||||
.map((item) => (
|
||||
<tr className="odd" key={item.id}>
|
||||
<td className="sorting_1" colSpan={2}>
|
||||
|
@ -33,7 +33,29 @@ const ProjectList = () =>
|
||||
|
||||
|
||||
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 ] );
|
||||
|
||||
@ -85,19 +107,7 @@ const ProjectList = () =>
|
||||
? Math.ceil(projectList.length / itemsPerPage)
|
||||
: 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 (
|
||||
<>
|
||||
@ -167,7 +177,7 @@ const ProjectList = () =>
|
||||
|
||||
|
||||
{currentItems &&
|
||||
sortedProjects.map((item) => (
|
||||
currentItems.map((item) => (
|
||||
<ProjectCard projectData={item} key={item.id}></ProjectCard>
|
||||
))}
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user