X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=www%2Fjs%2Fbook.js;h=796b04ed8b8d7e3caa5fed7433b0cf1430e7d135;hp=f6b0365993500449cc304a221a71c6ea39bc94a8;hb=c9abc8e62cc7ff5e71b16478d4561102fcc76fc6;hpb=f3d67feddf00f544e224f3f0a361b914578cdc63 diff --git a/www/js/book.js b/www/js/book.js index f6b0365..796b04e 100644 --- a/www/js/book.js +++ b/www/js/book.js @@ -55,6 +55,8 @@ var headings = [ [ "EloVar", TYPE_FLOAT ], [ "AWin%", TYPE_RATIO ], ]; +var sort_by = 1; +var direction = 1; var show_lines = function(data, game) { var moves = data['moves']; @@ -73,6 +75,17 @@ var show_lines = function(data, game) { var th = document.createElement("th"); headings_tr.append(th); $(th).text(headings[i][0]); + (function(new_sort_by) { + $(th).click(function() { + if (sort_by == new_sort_by) { + direction = -direction; + } else { + sort_by = new_sort_by; + direction = 1; + } + show_lines(data, game); + }); + })(i); } var lines = []; @@ -122,6 +135,8 @@ var show_lines = function(data, game) { lines.push(line); } + lines.sort(function(a, b) { return direction * ( b[sort_by] - a[sort_by]); }); + var tbl = $("#lines"); tbl.empty();