Skip to content

Fix tables using tablesorter.js so that date columns are sorted by time#3410

Merged
johannaengland merged 1 commit intoUninett:masterfrom
jorund1:fix-table-sorting
Aug 4, 2025
Merged

Fix tables using tablesorter.js so that date columns are sorted by time#3410
johannaengland merged 1 commit intoUninett:masterfrom
jorund1:fix-table-sorting

Conversation

@jorund1
Copy link
Copy Markdown
Collaborator

@jorund1 jorund1 commented Jul 24, 2025

Scope and purpose

tablesorter.js used in the thresholds threshold table and useradmin API-token table sorts date columns by their string value and not their numeric time value.

This PR makes it so that date columns are sorted by their numeric time value in these tables.

Urls:
/useradmin/tokens/
/threshold/

This pull request

  • Adds a new javascript file that adds a parser (for changing date strings to numeric time value) to the global $.tablesorter object. In contrast to the built-in parsers, this parser looks for a specific node attribute, instead of a node's text value.
  • Makes date columns in the thresholds threshold-table and useradmin API-token table use the new parser.
  • Disables sorting the last column in the thresholds threshold-table since it is just a column with icons.

Contributor Checklist

  • Added a changelog fragment for towncrier
  • Added/amended tests for new/changed code
  • Added/changed documentation
  • Linted/formatted the code with black and ruff, easiest by using pre-commit
  • The first line of the commit message continues the sentence "If applied, this commit will ...", starts with a capital letter, does not end with punctuation and is 50 characters or less long. See https://cbea.ms/git-commit/
  • This pull request is based on the correct upstream branch: For a patch/bugfix affecting the latest stable version, it should be based on that version's branch (<major>.<minor>.x). For a new feature or other additions, it should be based on master.
  • If applicable: Created new issues if this PR does not fix the issue completely/there is further work to be done
  • If this results in changes in the UI: Added screenshots of the before and after
  • If this adds a new Python source code file: Added the boilerplate header to that file

@johannaengland johannaengland requested a review from a team July 24, 2025 11:39
@jorund1 jorund1 changed the title Fix tables using tablesort.js so that date columns are sorted by time Fix tables using tablesorter.js so that date columns are sorted by time Jul 24, 2025
Copy link
Copy Markdown
Contributor

@johannaengland johannaengland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't really say anything about the JavaScript code itself, but I tested it and it works great!

@lunkwill42
Copy link
Copy Markdown
Member

The fact that this has become a problem at all, is it not related to #3369?

@johannaengland
Copy link
Copy Markdown
Contributor

johannaengland commented Jul 30, 2025

The fact that this has become a problem at all, is it not related to #3369?

No, it is directly related to it. Because beforehand it did not make a difference between sorting timestamps of the format "2025-04-26 13:00:00" by their string value instead of their numeric time value. But I think this change is generally nice to have, in case the date format changes again in the future :D

@lunkwill42
Copy link
Copy Markdown
Member

The fact that this has become a problem at all, is it not related to #3369?

No, it is directly related to it.

Exactly. That's one of the great advantages of ISO timestamps: They are both quite unambiguous and also easy to sort as if they were strings :-)

I like this fix, though I've now also posted #3412 based on your research.

Copy link
Copy Markdown
Member

@lunkwill42 lunkwill42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! :)

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Aug 4, 2025

@johannaengland johannaengland merged commit a118eef into Uninett:master Aug 4, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants