Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sorting by multiple columns in dataframe #10778

Merged
merged 19 commits into from
Mar 12, 2025
Merged

Allow sorting by multiple columns in dataframe #10778

merged 19 commits into from
Mar 12, 2025

Conversation

hannahblair
Copy link
Collaborator

@hannahblair hannahblair commented Mar 10, 2025

Description

Adds the ability to sort by up to three columns.

  • Shows the priority sort after more than one is selected
  • Also updates the sort buttons for better accessibility
  • The location of the priority # was pretty tricky. An alternative is to add another button to the Toolbar above the dataframe and allow you to select the columns to sort by -> logic moved to cell menu

Kapture 2025-03-11 at 22 53 51

Closes: #4981

🎯 PRs Should Target Issues

Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.

Not adhering to this guideline will result in the PR being closed.

Testing and Formatting Your Code

  1. PRs will only be merged if tests pass on CI. We recommend at least running the backend tests locally, please set up your Gradio environment locally and run the backed tests: bash scripts/run_backend_tests.sh

  2. Please run these bash scripts to automatically format your code: bash scripts/format_backend.sh, and (if you made any changes to non-Python files) bash scripts/format_frontend.sh

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Mar 10, 2025

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Storybook ready! Storybook preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-pypi-previews.s3.amazonaws.com/f726481dce358d07da18a4223793529a357792fb/gradio-5.20.1-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@f726481dce358d07da18a4223793529a357792fb#subdirectory=client/python"

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/f726481dce358d07da18a4223793529a357792fb/gradio-client-1.13.1.tgz

Use Lite from this PR

<script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/f726481dce358d07da18a4223793529a357792fb/dist/lite.js""></script>

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Mar 10, 2025

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/atoms minor
@gradio/core minor
@gradio/dataframe minor
gradio minor
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Allow sorting by multiple columns in dataframe

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@hannahblair hannahblair marked this pull request as ready for review March 11, 2025 13:51
@abidlabs
Copy link
Member

UI looks good to me! Is this completley ready for review @hannahblair? Perhaps I'm doing something wrong but I'm not seeing the sorting work reliably in demo/matrix_transpose:

Screen.Recording.2025-03-11.at.7.45.26.AM.mov
  • I would have expected that clicking on a sort arrow immediately turns it orange. But now it seems you have to click it twice to turn it orange. Is the idea that the orange signifies that the column sort is now locked? I think we should keep the single-click = orange, and then if you click on it again, the "1" icon should appear
  • As you can see in the video, sometimes I would click on a column sort twice, get the orange highlighting, but then when I would click on another column, the first column sort would disappear. The behavior was inconsistent. Edit: perhaps this is because I'm missing the sort arrow when clicking on the second column. Perhaps we can increase the target area a bit?
  • I believe the numbering is backwards -- the first column that is sorted should retain the "1" icon, the second should have the "2" icon, and so on. Right now, the final column you click has the "1" icon, etc.

@hannahblair
Copy link
Collaborator Author

@abidlabs can you give it another spin? think those points are addressed now.

@abidlabs
Copy link
Member

Nice @hannahblair! Yes all of those points are addressed, and the PR overall looks good to me. Just a couple of minor suggestions:

  • While I really appreciate that the sort icons are easier to click on now, for dataframes with many columns, the sort icons can appear crowded. What if we only showed the sort icons when a user hovers over the header of a column or if that column has a sort applied?
Screenshot 2025-03-11 at 8 39 04 AM
  • It seems that the sorts are not reset anymore when the dataframe value is reset. I think they should be:
Screen.Recording.2025-03-11.at.8.42.23.AM.mov

Copy link
Member

@abidlabs abidlabs left a comment

Choose a reason for hiding this comment

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

nice @hannahblair lgtm with a couple of minor things mentioned above!

Copy link
Member

@abidlabs abidlabs left a comment

Choose a reason for hiding this comment

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

Nice @hannahblair the UI looks really great!

@hannahblair hannahblair merged commit 373007b into main Mar 12, 2025
24 checks passed
@hannahblair hannahblair deleted the sort-by-cols branch March 12, 2025 09:42
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.

Add the option to sort a Dataframe by several columns
3 participants