An old acquaintance assisted me with the code below for occupation claims for writing forum and currently it alphabetizes names pulled from a member list but I would like it to alphabetized by EMPLOYER (.employer) instead, which appears beneath each “job-list” section.
Currently it sorts alphabetically by character/name:
“District Businesses
Labrinyth John Doe
Cascade Karen Doe”
but I would like it to be alphabetical by employer:
“District Businesses
Cascade Karen Doe
Labrinyth John Doe”
const name1 = [
["Name1 Businesses"]
];
const name2 = [
["Name2 Businesses"]
];
const name3 = [
["Title1"],
["Name 3 Businesses"]
];
const name4 = [
["Title2"],
["Name 4 Businesses"]
];
const jobslist = [name1, name2, name3, name4];
function getCharacters() {
$.get("/index.php?act=Members&max_results=1000&", function (data) {
var doc = new DOMParser().parseFromString(data, 'text/html');
$(".claims-info:not(.Admin):not(.Staff):not(.OOC):not(.Archived):not(.Applying)", doc).each(function () {
let job = $(this).find('.employer').text();
if (job == '') job = "Other";
let claim = $(this).find('.occupation').text();
let employer = $(this).find('.employer').text();
jobslist.forEach((district) => {
district.forEach((e) => {
if (e[0] == job) {
e.push(`${claim} ${$(this).find('.name').html()}</p>`)
}
});
});
});
let group = 0
jobslist.forEach((district) => {
listName = getList(group)[1];
jobs = getList(group)[0];
district.forEach((job) => {
$('#dirjobs' + listName).append(`<div class="contentnote" id="${job[0].replace(/[ ']/g, '')}"><h2>${job[0]} <line></line></h2><div class="job-list"></div></div>`);
job.slice(1).forEach((claim) => {
$(`#${job[0].replace(/[ ']/g, '')} .job-list`).append(claim);
});
});
group++;
});
});
}
function getList(a) {
switch (a) {
case 0:
return [name1, 'name1']
break;
case 1:
return [name2, 'name2']
break;
case 2:
return [name3, 'name3']
break;
case 3:
return [name4, 'name4']
break;
default:
console.log('list not defined')
}
}
getCharacters();
I’ve tried implementing sort elements but with no luck, likely because I am not targeting the correct thing (as I have managed to change other sections, but not the employer section I’m trying to change). I am VERY MUCH a novice but learning quite a bit as I go but this is beyond my abilities at the moment. Can anyone assist with suggestions on how to best do this? Thank you in advance!