From 3caf7fc8de1a18c8e4d61a269cd1199a68fb823e Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 28 Nov 2022 12:20:51 +0100 Subject: html: save sorting order between refreshes --- html/index.html | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/html/index.html b/html/index.html index fd8d383..0300a18 100644 --- a/html/index.html +++ b/html/index.html @@ -64,7 +64,7 @@ td, th[scope="row"] { - +
@@ -361,6 +361,7 @@ function peers_show() { data['result']['peers'].forEach(function(peer) { formatter.add_row(peer); }); + peers_table_sort(); } var aliases = {}; @@ -405,7 +406,39 @@ function loop() { }, update_interval_seconds * 1000); } +// The number of the column last used for sorting (1-based indexing). +// A positive number means ascending order; negative number means descending +// order. +var peers_last_sorted_by = 0; + +function peers_table_sort() { + if (!peers_last_sorted_by) + return; + + let th = document.querySelector(`#peers thead tr :nth-child(${Math.abs(peers_last_sorted_by)})`); + th.click(); + th.click(); +} + +function peers_table_save_sorting(th) { + let idx = th.cellIndex + 1; + if (Math.abs(peers_last_sorted_by) == idx) { + peers_last_sorted_by = -peers_last_sorted_by; + } else { + peers_last_sorted_by = idx; + } +} + +function peers_table_setup() { + document.querySelectorAll('#peers th').forEach(function(th) { + th.addEventListener('click', function(event) { + peers_table_save_sorting(event.target); + }, false); + }); +} + function main() { + peers_table_setup(); update(); loop(); } -- cgit v1.2.3
Peer