My challenge involves handling an array of employee information that is organized by comparing the subdepartment of each employee to the priority of subdepartments within a particular department.
When a user clicks on an employee's name in an index, the system uses their department (stored as a data attribute) to retrieve all other employees in the same department. This collection is then sorted based on the manual assignment of subdepartment priorities in another array.
var results = $.grep(data, function(employee) {
if(employee.DEPT == dept) {
return employee.DEPT = dept;
}
});
// ** PLEASE NOTE: 'deptorder' is "Department" : [ "Subdepartment1", "Subdepartment2" ] defined manually
// Choose the order of subdepartments based on the department
order = deptorder[dept];
The initial sorting process:
results.sort(function(a, b) {
return $.inArray(a.SUBDEPT, order) - $.inArray(b.SUBDEPT, order);
});
After the initial sort, I need to structure the employees within each subdepartment group. The goal is to identify a 'manager' and have them displayed first within the grid for that specific subdepartment. Subsequently, other employees can be arranged alphabetically or using any other criterion.
I am seeking advice on how to perform a second round of sorting to achieve this desired outcome. Currently, managers are distinguished by having an employee.MANAGER attribute set to '1', while others have it blank.
I attempted the following approach:
results.sort(function(a, b) {
return (a.MANAGER == 1) - b;
});
Unfortunately, this method did not yield the expected results. The sorting mechanism described above represents my limited experience with employing the sort function. Any guidance would be greatly appreciated!