Looking to create my own website using C#, I'm currently working on sorting a list of names obtained from the database in alphabetical order (A - Z).
Check out this jsfiddle for an example and the JavaScript function I've written to populate a dropdown list with the list of people.
function loadResponsable() {
const url = document.getElementById("responsables").value;
document.getElementById("AssignDiv").style.display = "block";
$.ajax({
url: url,
type: "POST",
dataType: "json",
success: function(data) {
const responsables = document.getElementById("ticketRespInput");
for (let idx in data) {
if (data.hasOwnProperty(idx)) {
const option = document.createElement("option");
option.innerHTML = data[idx];
option.value = idx;
responsables.options.add(option);
}
}
}
});
};
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="form-group" name="asignar" id="AssignDiv">
<label class="required-field" name="asignar" id="lblAssignDiv" for="ticketRespInput">Asignado a:</label>
<select onchange="validate(this)" id="ticketRespInput" name="assigned" class="form-control form-control-user validateable" style="width: 100%; padding: 0.375rem 0.75rem; height: 50px;" tabindex="-1" aria-hidden="true">
<option value="" disabled selected>Sin asignar</option>
</select>
</div>
UPDATE:
Added some server-side code that fetches responsible users based on user groups.
[HttpPost]
public JsonResult LoadResponsables()
{
var groups = new List<string>();
if (string.Equals(Session["tipo"].ToString(), "super") ||
string.Equals(Session["tipo"].ToString(), "admin"))
groups.AddRange(LdapGroupModel.GetAllLdapGoups().LdapGroupsList
.Select(ldapGroup => ldapGroup.LdapGroupsId));
else
groups.AddRange(LdapGroupModel.GetLdapGroupsFromArea(Session["area"].ToString()).LdapGroupFromArea
.Select(ldapGroup => ldapGroup.LdapGroupsId));
return Json(LdapController.GetUsersByGroup(groups));
}
Error: