🆕 Sorting in the Network tables #713
Some checks are pending
docker / docker_dev (push) Waiting to run

This commit is contained in:
jokob-sk
2024-06-23 10:45:15 +10:00
parent 01e97e152c
commit a030912f48
3 changed files with 65 additions and 11 deletions

View File

@@ -270,6 +270,43 @@ function copyToClipboard(buttonElement) {
}
}
// -----------------------------------------------------------------------------
// Simple Sortable Table columns
// -----------------------------------------------------------------------------
function sortColumn(element) {
var th = $(element).closest('th');
var table = th.closest('table');
var columnIndex = th.index();
var ascending = !th.data('asc');
sortTable(table, columnIndex, ascending);
th.data('asc', ascending);
}
function sortTable(table, columnIndex, ascending) {
var tbody = table.find('tbody');
var rows = tbody.find('tr').toArray().sort(comparer(columnIndex));
if (!ascending) {
rows = rows.reverse();
}
for (var i = 0; i < rows.length; i++) {
tbody.append(rows[i]);
}
}
function comparer(index) {
return function(a, b) {
var valA = getCellValue(a, index);
var valB = getCellValue(b, index);
return $.isNumeric(valA) && $.isNumeric(valB) ? valA - valB : valA.localeCompare(valB);
};
}
function getCellValue(row, index) {
return $(row).children('td').eq(index).text();
}
// -----------------------------------------------------------------------------
// initialize
// -----------------------------------------------------------------------------