Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mayagbarnes
Copy link
Collaborator

@mayagbarnes mayagbarnes commented May 14, 2025

Describe your changes

st.dataframe: on sort (via dropdown) clear the selected row(s) consistent with the column header sort behavior.

Currently, when the data in the table is reordered via sorting, the selected row (ex: row 1) persists - so even though the previously selected data is not in row 1 anymore, row 1 still shows as selected.

GitHub Issue Link (if applicable)

Closes #11345

Testing Plan

  • E2E Tests: ✅ Added
  • Manual Testing: ✅

@mayagbarnes mayagbarnes added security-assessment-completed Security assessment has been completed for PR change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels May 14, 2025
@snyk-io
Copy link
Contributor

snyk-io bot commented May 14, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@github-actions
Copy link
Contributor

github-actions bot commented May 14, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-11363/streamlit-1.45.1-py3-none-any.whl
🕹️ Preview app pr-11363.streamlit.app (☁️ Deploy here if not accessible)

// Keeping row selections when sorting columns is not supported at the moment.
// So we need to clear the selected rows before we do the sorting (Issue #11345).
// Maintain column selections as these are not impacted.
clearSelection(false, true)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Think it makes sense here to only clear row selections while maintaining column selections, but lmk if alternative thoughts

@mayagbarnes mayagbarnes marked this pull request as ready for review May 19, 2025 21:46
@lukasmasuch lukasmasuch requested a review from Copilot May 20, 2025 20:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue in st.dataframe where row selections persist after sorting via dropdown, ensuring that only column selections remain. Key changes include:

  • Updating DataFrame.tsx to clear row selections on dropdown sort.
  • Renaming and reordering test helper functions in the Playwright tests.
  • Adding new E2E tests to verify the updated selection behavior.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
frontend/lib/src/components/widgets/DataFrame/DataFrame.tsx Implements conditional clearing of row selections before sorting
e2e_playwright/st_dataframe_selections_test.py Renames helper functions and adds tests for single-row selection behavior on sort
e2e_playwright/st_dataframe_selections.py Adds a new section for testing single-row & single-column selection
Comments suppressed due to low confidence (2)

e2e_playwright/st_dataframe_selections_test.py:56

  • The renaming of the test helper function should be double-checked to ensure it accurately reflects its purpose and corresponds to the correct DataFrame index in the UI.
def _get_single_row_and_column_select_df(app: Page) -> Locator:

e2e_playwright/st_dataframe_selections_test.py:57

  • Verify that the updated nth index in the helper function aligns with the intended DataFrame instance for this test scenario to avoid misreferencing.
return app.get_by_test_id("stDataFrame").nth(5)

Copy link
Collaborator

@lukasmasuch lukasmasuch left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@mayagbarnes mayagbarnes merged commit eb840da into develop May 20, 2025
38 checks passed
@mayagbarnes mayagbarnes deleted the dataframe-sort branch May 20, 2025 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: st.dataframe returns incorrect row selections after dataframe is sorted with dropdown menu

3 participants