Skip to content

fix: style_cell and hover_template lost when sorting in descending order#8915

Open
ManasVardhan wants to merge 2 commits intomarimo-team:mainfrom
ManasVardhan:fix/style-cell-descending-sort
Open

fix: style_cell and hover_template lost when sorting in descending order#8915
ManasVardhan wants to merge 2 commits intomarimo-team:mainfrom
ManasVardhan:fix/style-cell-descending-sort

Conversation

@ManasVardhan
Copy link
Copy Markdown

Summary

Fixes #8847. style_cell styles (and hover_template texts) were lost when sorting a table in descending order.

Root Cause

_style_cells() and _hover_cells() generated row IDs assuming they correlated with the sort order:

  • Ascending: range(skip, skip + take)
  • Descending: range(total - 1 - skip, ..., -1)

This only worked when sorting by the index column. When sorting by any other column, the actual _marimo_row_id values on the displayed page are arbitrary and do not follow sequential or reversed-sequential patterns. The frontend looks up styles by _marimo_row_id, so the mismatched keys caused all styles to be silently discarded.

Fix

Introduces _get_page_row_ids() which reads the actual _marimo_row_id values from the sorted _searched_manager data for the current page. This ensures style/hover dict keys always match what the frontend uses for lookup, regardless of sort column or direction.

For tables without stable row IDs (list/dict data), positional indices are returned since both backend and frontend use positional indexing.

The descending parameter is removed from _style_cells() and _hover_cells() since it is no longer needed.

Additional fixes

  • Removes xfail from test_cell_search_df_hover_texts_sorted (hover with sorted data now works)
  • Fixes pre-existing test bug where sort was passed as a bare SortArgs instead of [SortArgs(...)]

Tests

  • test_cell_styles_descending_non_index_column: 4-row table sorted by Score (not index) descending. Verifies all row IDs present with correct style values.
  • test_cell_styles_sorted_by_value_with_pagination: 20-row table sorted by Value descending with page_size=5. Verifies page 0 contains the correct (non-sequential) row IDs.
  • All existing style/hover tests continue to pass.

When sorting by any column, _style_cells() and _hover_cells() generated
sequential row IDs (or reversed sequential IDs for descending) that did
not match the actual _marimo_row_id values of the displayed rows. This
caused the frontend to discard all styles/hover texts because the dict
keys did not match its row ID lookups.

The fix introduces _get_page_row_ids() which reads actual _marimo_row_id
values from the sorted searched manager data for the current page. This
ensures style/hover dict keys always match what the frontend expects,
regardless of sort column or direction.

The descending parameter is removed from _style_cells() and
_hover_cells() since it is no longer needed.

Also fixes hover_template with sorted data (previously marked xfail)
and fixes the pre-existing test bug where sort arg was passed as a
single SortArgs instead of a list.

Closes marimo-team#8847
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 29, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Mar 29, 2026 0:50am

Request Review

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 29, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@ManasVardhan
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

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.

style_cell styles lost when sorting table in descending order

1 participant