From c291a82b0127048d3aa969f82d42d29acb142ea2 Mon Sep 17 00:00:00 2001
From: zsloan
Date: Wed, 30 Sep 2020 14:59:30 -0500
Subject: Fixed issue where columns sorted by inner text (text inside link
tags) didn't sort all rows when a table is paginated and has more than one
page
* wqflask/wqflask/static/new/javascript/search_results.js - Added
"extract_inner_text" function for getting the inner text from a string
containing HTML in order to avoid using DataTables' orderDataType (which
can only fetch values directly from the DOM, which is why sorting wasn't
working with multiple pages), and also included this function in the
"natural-minus-na" data type (so columns can be sorted that contain both
HTML/links and N/A values)
* wqflask/wqflask/templates/collections/view.html - Changed record column
to use "natural-minus-na" sort method in order to fix the inner-text
sorting issue + added sorting to the checkbox column (in the same way as
it already works in the search result page)
* wqflask/wqflask/templates/search_results_page.html - Replaced the
columns that used orderDataType with using the updated
"natural-minus-na" data type
* wqflask/wqflask/templates/correlation_page.html - Fixed issue where
N/As in the Year column (for phenotype correlations) were still displayed as links
---
wqflask/wqflask/static/new/javascript/search_results.js | 10 ++++++++--
wqflask/wqflask/templates/collections/view.html | 14 +++++++-------
wqflask/wqflask/templates/correlation_page.html | 4 ++++
wqflask/wqflask/templates/search_result_page.html | 9 +--------
4 files changed, 20 insertions(+), 17 deletions(-)
(limited to 'wqflask')
diff --git a/wqflask/wqflask/static/new/javascript/search_results.js b/wqflask/wqflask/static/new/javascript/search_results.js
index 61134a88..86660126 100644
--- a/wqflask/wqflask/static/new/javascript/search_results.js
+++ b/wqflask/wqflask/static/new/javascript/search_results.js
@@ -261,6 +261,12 @@ $(function() {
let na_equivalent_vals = ["N/A", "--", ""]; //ZS: Since there are multiple values that should be treated the same as N/A
+ function extract_inner_text(the_string){
+ var span = document.createElement('span');
+ span.innerHTML = the_string;
+ return span.textContent || span.innerText;
+ }
+
function sort_NAs(a, b, sort_function){
if ( na_equivalent_vals.includes(a) && na_equivalent_vals.includes(b)) {
return 0;
@@ -276,10 +282,10 @@ $(function() {
$.extend( $.fn.dataTableExt.oSort, {
"natural-minus-na-asc": function (a, b) {
- return sort_NAs(a, b, naturalAsc)
+ return sort_NAs(extract_inner_text(a), extract_inner_text(b), naturalAsc)
},
"natural-minus-na-desc": function (a, b) {
- return sort_NAs(a, b, naturalDesc)
+ return sort_NAs(extract_inner_text(a), extract_inner_text(b), naturalDesc)
}
});
diff --git a/wqflask/wqflask/templates/collections/view.html b/wqflask/wqflask/templates/collections/view.html
index ca8aece3..bc487a59 100644
--- a/wqflask/wqflask/templates/collections/view.html
+++ b/wqflask/wqflask/templates/collections/view.html
@@ -164,13 +164,13 @@
{% block js %}
-
+