Edit this page | Blame

Sort by Attributes

Tags

  • assigned: zachs, fredm
  • type: feature-request, feature request
  • priority: high
  • status: closed
  • keywords: genenetwork2, sorting, attributes

Description

From the email:

This trait: https://genenetwork.org/show_trait?trait_id=L2229-L8228&dataset=Duke_UTHSC_ConnStrgROIs4zlog2_0524 I want to sort by the attribute Age, from youngest to oldest but all of the NULL values are treated as the lowest value. I would much prefer sorting to ignore these empty fields..

Javascript is weird, and we'd have to do something like the following to sort with ages:

myarr.toSorted((a, b) => {
    if(a == null) {/*isNumber(null) = true*/
        return 1;
    }
    if(b == null) {
        return -1;
    }
    if(isNumber(a) && isNumber(b)) {
        return a - b;
    }
});


to ensure that null values always come last.

Mixed lists are going to have to be sorted in alphabetical order, I guess, while still ensuring nulls end up last with something like the above.

Fixed

With commit https://github.com/genenetwork/genenetwork2/commit/4c4d91d03a873969315727918206097a0d89bb19

The sort functions in search_results.js were moved into table_functions.js so they could be used by more pages. In this case, the trait page needed access so that the case attribute columns could be sorted such that NA/NULL value are always at the bottom.

(made with skribilo)