fix onlinelist sorting inshallah
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
window.onbeforeunload = () => { window.scrollTo(0, 0); }
|
||||
$(document).ready(function () { mp.trigger('CEF:PlayerList_Loaded'); });
|
||||
|
||||
setPlayerCount = (factionId, value) => {
|
||||
if (factionId == -1) {
|
||||
document.getElementById('player-count').innerHTML = value;
|
||||
addTableSorting();
|
||||
} else if (factionId >= 0 && factionId <= 9) {
|
||||
document.getElementById(factionId).innerHTML = value;
|
||||
}
|
||||
@@ -28,33 +28,4 @@ function addPlayerEntry(userId, userName, factionId, userPing) {
|
||||
document.getElementById('players').innerHTML += `<tr><td>${userId}</td> <td>${userName}</td> <td class="group group--${factionId}">${factionName}</td> <td>${userPing}</td></tr>`;
|
||||
}
|
||||
|
||||
// https://www.jstips.co/en/javascript/detect-document-ready-in-pure-js/
|
||||
document.onreadystatechange = () => {
|
||||
if (document.readyState === 'complete') { mp.trigger('CEF:PlayerList_Loaded'); }
|
||||
};
|
||||
|
||||
// Sortierung von https://codepen.io/selbekk/pen/LNOZKL
|
||||
function addTableSorting() {
|
||||
const headers = Array.from(document.querySelectorAll('th'));
|
||||
const rows = Array.from(document.querySelectorAll('tbody tr'));
|
||||
|
||||
function sort(e) {
|
||||
const index = headers.indexOf(e.target);
|
||||
const sortVal = e.target.classList.contains('is-asc') ? 1 : -1;
|
||||
rows.sort((a, b) => {
|
||||
const aValue = a.children[index].innerHTML;
|
||||
const bValue = b.children[index].innerHTML;
|
||||
if(aValue > bValue) { return sortVal; }
|
||||
if(aValue < bValue) { return -sortVal; }
|
||||
return 0;
|
||||
})
|
||||
|
||||
e.target.classList.add('is-sorted');
|
||||
e.target.classList.toggle('is-asc');
|
||||
const body = document.querySelector('tbody');
|
||||
body.innerHTML = '';
|
||||
rows.forEach(row => body.appendChild(row));
|
||||
}
|
||||
|
||||
headers.forEach(header => header.addEventListener('click', sort));
|
||||
}
|
||||
$("table").stupidtable();
|
||||
|
||||
Reference in New Issue
Block a user