From 20dae626debac91f737473175b372c27b931f283 Mon Sep 17 00:00:00 2001 From: Udo Walter Date: Wed, 13 Sep 2017 13:57:20 +0200 Subject: [js_stupidtable] fixed stupidtable not working with collapsed tables --- .../exams/templates/page-upcoming-lectures.html | 4 +--- modules-available/js_stupidtable/clientscript.js | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'modules-available') diff --git a/modules-available/exams/templates/page-upcoming-lectures.html b/modules-available/exams/templates/page-upcoming-lectures.html index bea53ad0..8ff8143e 100644 --- a/modules-available/exams/templates/page-upcoming-lectures.html +++ b/modules-available/exams/templates/page-upcoming-lectures.html @@ -39,8 +39,6 @@ {{/pending_lectures}} - - {{#decollapse}} @@ -50,7 +48,7 @@ {{/decollapse}} - + diff --git a/modules-available/js_stupidtable/clientscript.js b/modules-available/js_stupidtable/clientscript.js index 4e0dd4c9..8b8fc107 100644 --- a/modules-available/js_stupidtable/clientscript.js +++ b/modules-available/js_stupidtable/clientscript.js @@ -97,7 +97,8 @@ var column = []; var sortFns = $table.data('sortFns'); var sortMethod = sortFns[datatype]; - var trs = $table.children("tbody").children("tr"); + var collapsedCount = $table.children("tbody").children("tr.collapse").length; + var trs = $table.children("tbody").children("tr:not(.slx-decollapse)"); // Extract the data for the column that needs to be sorted and pair it up // with the TR itself into a tuple. This way sorting the values will @@ -124,7 +125,19 @@ // Replace the content of tbody with the sorted rows. Strangely // enough, .append accomplishes this for us. trs = $.map(column, function(kv) { return kv[1]; }); - $table.children("tbody").append(trs); + + if (collapsedCount > 0) { + var showCount = trs.length - collapsedCount; + for (var i = 0; i < trs.length; i++) { + if (i < showCount) { + $(trs[i]).removeClass("collapse"); + } else { + $(trs[i]).addClass("collapse"); + } + } + } + + $table.children("tbody").prepend(trs); // Reset siblings $table.find("th").data("sort-dir", null).removeClass("sorting-desc sorting-asc"); -- cgit v1.2.3-55-g7522