diff options
author | zsloan | 2024-05-31 21:17:30 +0000 |
---|---|---|
committer | zsloan | 2024-05-31 21:21:44 +0000 |
commit | 4c4d91d03a873969315727918206097a0d89bb19 (patch) | |
tree | f2079c01bb71f54b99b20cb60cca0e9a7a220a99 /gn2/wqflask/static | |
parent | 084c82685ca1b85648d7cd48672c3c0ecf2a49fd (diff) | |
download | genenetwork2-4c4d91d03a873969315727918206097a0d89bb19.tar.gz |
Enable NA sorting for case attributes
The NA-excluding sort functions were moved to
table_functions.js (and removed from search_results.js)
so they can be used by other pages (in this case the
show_trait page)
Diffstat (limited to 'gn2/wqflask/static')
3 files changed, 48 insertions, 48 deletions
diff --git a/gn2/wqflask/static/new/javascript/initialize_show_trait_tables.js b/gn2/wqflask/static/new/javascript/initialize_show_trait_tables.js index 44076c17..970a49a3 100644 --- a/gn2/wqflask/static/new/javascript/initialize_show_trait_tables.js +++ b/gn2/wqflask/static/new/javascript/initialize_show_trait_tables.js @@ -141,7 +141,7 @@ buildColumns = function() { columnList.push( { 'title': "<div title='" + js_data.attributes[attrKeys[i]].description + "' style='text-align: " + js_data.attributes[attrKeys[i]].alignment + "'>" + js_data.attributes[attrKeys[i]].name + "</div>", - 'type': "natural", + 'type': "natural-minus-na", 'data': null, 'targets': attrStart + i, 'render': function(data, type, row, meta) { diff --git a/gn2/wqflask/static/new/javascript/search_results.js b/gn2/wqflask/static/new/javascript/search_results.js index c263ef49..29050c2b 100644 --- a/gn2/wqflask/static/new/javascript/search_results.js +++ b/gn2/wqflask/static/new/javascript/search_results.js @@ -325,53 +325,6 @@ $(function() { $("#export_traits").click(exportTraits); $("#export_collection").click(exportCollection); - let naturalAsc = $.fn.dataTableExt.oSort["natural-ci-asc"] - let naturalDesc = $.fn.dataTableExt.oSort["natural-ci-desc"] - - let na_equivalent_vals = ["N/A", "--", ""]; //ZS: Since there are multiple values that should be treated the same as N/A - - function extractInnerText(the_string){ - var span = document.createElement('span'); - span.innerHTML = the_string; - return span.textContent || span.innerText; - } - - function sortNAs(a, b, sort_function){ - if ( na_equivalent_vals.includes(a) && na_equivalent_vals.includes(b)) { - return 0; - } - if (na_equivalent_vals.includes(a)){ - return 1 - } - if (na_equivalent_vals.includes(b)) { - return -1; - } - return sort_function(a, b) - } - - $.extend( $.fn.dataTableExt.oSort, { - "natural-minus-na-asc": function (a, b) { - return sortNAs(extractInnerText(a), extractInnerText(b), naturalAsc) - }, - "natural-minus-na-desc": function (a, b) { - return sortNAs(extractInnerText(a), extractInnerText(b), naturalDesc) - } - }); - - $.fn.dataTable.ext.order['dom-checkbox'] = function ( settings, col ) - { - return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) { - return $('input', td).prop('checked') ? '1' : '0'; - } ); - }; - - $.fn.dataTable.ext.order['dom-inner-text'] = function ( settings, col ) - { - return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) { - return $(td).text(); - } ); - } - applyDefault = function() { let default_collection_id = $.cookie('default_collection'); if (default_collection_id) { diff --git a/gn2/wqflask/static/new/javascript/table_functions.js b/gn2/wqflask/static/new/javascript/table_functions.js index 62888cd9..a648778e 100644 --- a/gn2/wqflask/static/new/javascript/table_functions.js +++ b/gn2/wqflask/static/new/javascript/table_functions.js @@ -88,3 +88,50 @@ function saveColumnSettings(tableId, traitTable) { // Save (or update) the settings in localStorage localStorage.setItem(tableId, JSON.stringify(userColumnDefs)); } + +let naturalAsc = $.fn.dataTableExt.oSort["natural-ci-asc"] +let naturalDesc = $.fn.dataTableExt.oSort["natural-ci-desc"] + +let na_equivalent_vals = ["N/A", "--", "", "NULL"]; //ZS: Since there are multiple values that should be treated the same as N/A + +function extractInnerText(the_string){ + var span = document.createElement('span'); + span.innerHTML = the_string; + return span.textContent || span.innerText; +} + +function sortNAs(a, b, sort_function){ + if ( na_equivalent_vals.includes(a) && na_equivalent_vals.includes(b)) { + return 0; + } + if (na_equivalent_vals.includes(a)){ + return 1 + } + if (na_equivalent_vals.includes(b)) { + return -1; + } + return sort_function(a, b) +} + +$.extend( $.fn.dataTableExt.oSort, { + "natural-minus-na-asc": function (a, b) { + return sortNAs(extractInnerText(a), extractInnerText(b), naturalAsc) + }, + "natural-minus-na-desc": function (a, b) { + return sortNAs(extractInnerText(a), extractInnerText(b), naturalDesc) + } +}); + +$.fn.dataTable.ext.order['dom-checkbox'] = function ( settings, col ) +{ + return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) { + return $('input', td).prop('checked') ? '1' : '0'; + } ); +}; + +$.fn.dataTable.ext.order['dom-inner-text'] = function ( settings, col ) +{ + return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) { + return $(td).text(); + } ); +}
\ No newline at end of file |