Skip to content

Feat: Automatically hide row indices in st.dataframe when row selection is active#12448

Merged
lukasmasuch merged 5 commits intostreamlit:developfrom
plumol:feature/hide_row_index_on_selection
Sep 19, 2025
Merged

Feat: Automatically hide row indices in st.dataframe when row selection is active#12448
lukasmasuch merged 5 commits intostreamlit:developfrom
plumol:feature/hide_row_index_on_selection

Conversation

@plumol
Copy link
Copy Markdown
Contributor

@plumol plumol commented Sep 5, 2025

Describe your changes

Implements the suggestion that range indices in st.dataframe should be hidden automatically when row selections are active and hide_index is not set or is not false.

Allows users to enable the index column via hide_index=False.

Image render link provided in the original issue: #12237 (comment)

import streamlit as st
import pandas as pd


df = pd.DataFrame({
  'first column': [1, 2, 3, 4],
  'second column': [10, 20, 30, 40],
  'third column': [10, 20, 30, 40],
  'fourth column': [10, 20, 30, 40],
})

st.dataframe(
  df,
  on_select="rerun",
  # hide_index=False, # can set hide_index=False to re-enable the range index
  selection_mode="single-row" # works on either single-row or multi-row options
)

GitHub Issue Link (if applicable)

Implementation of the suggestion listed here: #12237

Testing Plan

  • Unit Tests (JS and/or Python)
  • E2E Tests

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Sep 5, 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)

@lukasmasuch lukasmasuch added feature:st.dataframe Related to the `st.dataframe` element impact:users PR changes affect end users status:needs-product-approval PR requires product approval before merging labels Sep 8, 2025
@lukasmasuch lukasmasuch requested a review from Copilot September 8, 2025 18:16
@lukasmasuch lukasmasuch added change:feature PR contains new feature or enhancement implementation and removed feature:st.dataframe Related to the `st.dataframe` element labels Sep 8, 2025
Copy link
Copy Markdown
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 implements automatic hiding of row indices in st.dataframe when row selection is active, improving the user experience by reducing visual clutter while still allowing manual override via hide_index=False.

Key Changes

  • Automatically hides the index column when row selection modes ("single-row" or "multi-row") are active
  • Preserves user control by allowing hide_index=False to explicitly show the index
  • Implementation follows the existing column configuration pattern
Comments suppressed due to low confidence (1)

lib/streamlit/elements/arrow.py:715

  • The automatic hiding logic should only apply when hide_index is not explicitly set by the user. Currently, this code will hide the index even when hide_index=False is explicitly passed, and then the subsequent check will override it. The condition should be if is_selection_activated and selection_mode in [\"multi-row\", \"single-row\"] and hide_index is None: to respect explicit user preferences.
        if is_selection_activated and selection_mode in ["multi-row", "single-row"]:
            update_column_config(
                column_config_mapping, INDEX_IDENTIFIER, {"hidden": True}
            )
        if hide_index is not None:
            update_column_config(
                column_config_mapping, INDEX_IDENTIFIER, {"hidden": hide_index}
            )

@plumol plumol marked this pull request as ready for review September 18, 2025 17:24
@jrieke
Copy link
Copy Markdown
Collaborator

jrieke commented Sep 19, 2025

Behavior looks good! Could maybe add a sentence on this behavior to the docstring of hide_index but up to @sfc-gh-dmatthews. Will get our eng team to give this a code review :)

@jrieke jrieke added status:product-approved Community PR is approved by product team and removed status:needs-product-approval PR requires product approval before merging labels Sep 19, 2025
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Copy link
Copy Markdown
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 👍 I added a couple of tweaks and tests

@lukasmasuch lukasmasuch merged commit 92b87df into streamlit:develop Sep 19, 2025
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users status:product-approved Community PR is approved by product team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants