diff options
author | zsloan | 2024-05-31 21:17:30 +0000 |
---|---|---|
committer | Alexander_Kabui | 2024-08-28 15:02:45 +0300 |
commit | 385b6b861e6586bf1dd985b3aa416124835f07a1 (patch) | |
tree | f4cc82c00607dc33d636c8f11c47ecd8c2228a93 /gn2/wqflask/static/new/javascript/table_functions.js | |
parent | 32832d2a78485b1180c4bebb16aa8f3723851b6d (diff) | |
download | genenetwork2-385b6b861e6586bf1dd985b3aa416124835f07a1.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/new/javascript/table_functions.js')
-rw-r--r-- | gn2/wqflask/static/new/javascript/table_functions.js | 47 |
1 files changed, 47 insertions, 0 deletions
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 |