Skip to content

Sort a data-table column once per heading click - #90

Merged
thunderballfists merged 2 commits into
mainfrom
fix/header-click-sorts-once
Sep 30, 2026
Merged

thunderballfists merged 2 commits into
mainfrom
fix/header-click-sorts-once

Conversation

@thunderballfists

Copy link
Copy Markdown
Owner

Clicking a data-table column heading delivers HeaderSelected twice, so the ascending/descending toggle always ends on descending and a table can never be sorted ascending by clicking.

Measured on current main (f8e472c) with real pointer clicks on the second heading of a small table:

click 1 -> HeaderSelected [1, 1]  rows ['a', 'c', 'b']  N ↓
click 2 -> HeaderSelected [1, 1]  rows ['a', 'c', 'b']  N ↓
click 3 -> HeaderSelected [1, 1]  rows ['a', 'c', 'b']  N ↓

With this change:

click 1 -> HeaderSelected [1]  rows ['b', 'c', 'a']  N ↑
click 2 -> HeaderSelected [1]  rows ['a', 'c', 'b']  N ↓
click 3 -> HeaderSelected [1]  rows ['b', 'c', 'a']  N ↑

Cause. Textual calls the _on_* handler of every class in the MRO. SeededDataTable._on_click and _on_mouse_move also called super(), which runs DataTable's own handler a second time.

Fix. Neither handler calls super() any more. _on_click only has to swallow the click that ends a resize press, and does that with event.prevent_default(), which is what keeps DataTable's handler from running for it. The resize-hover update in _on_mouse_move (from #87) is kept.

Tests (both use real Pilot clicks and both fail on main without the change):

  • one click posts exactly one HeaderSelected, and repeated clicks toggle ascending, descending, ascending;
  • the click that ends a resize press does not sort, and the next ordinary click does.

This was found by an application's test suite, which sorts tables by heading and fails against main; it passes against this branch.

Validation:

  • full headless suite, Python 3.13 on macOS: 391 passed
  • pyflakes textui: clean
  • visual tests in a python:3.12-slim container with Textual 8.2.8: 6 passed (no snapshot changes)
  • GitHub Actions on this PR covers Python 3.11, 3.12, 3.14, lint and visual

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 10721c3744

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread textui/widgets/data_widgets.py Outdated
@thunderballfists
thunderballfists merged commit 9c8f704 into main Sep 30, 2026
17 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant