Skip to content

DataTable: add summary statistics for selected cells#8326

Open
andrewsoonqn wants to merge 17 commits intomarimo-team:mainfrom
andrewsoonqn:data-table-selection-stats
Open

DataTable: add summary statistics for selected cells#8326
andrewsoonqn wants to merge 17 commits intomarimo-team:mainfrom
andrewsoonqn:data-table-selection-stats

Conversation

@andrewsoonqn
Copy link
Contributor

@andrewsoonqn andrewsoonqn commented Feb 16, 2026

📝 Summary

Closes #6015

Introduce summary statistics for selected cells to the data table component. When users select two or more cells, the UI now displays the count, sum, and average of the selected numeric values.

image

Demo:

cell-selection-data.mov

Works also with other components where DataTable is used, e.g., dataframes.

data-frame-selection-data.mov

🔍 Description of Changes

Decisions made:

  • Non-numeric data is included in Count only, and not included in calculation of Sum and Average
    • Empty cells, infinity, NaN, object, boolean, empty or practically empty (e.g. " ") strings are considered non-numeric
    • Numeric strings are considered numeric, e.g. the entry below shows up as a number in the table
    {"name": "Alice", "age": 30, "city": "New York", "balance": "100"},
image
  • The checkbox column to select rows is not included in any stats
  • Sum and Average are shown only when the selection contains at least one numeric value.
  • The CellSelectionStats component only shows when 2 or more cells are selected
  • Have a layout shift and add a new bottom row (like what search does when clicked)
  • Calculated stats are rounded to max 8 decimal points

Future considerations:

  • I have not implemented a way to disable this display. One suggestion is that we can add a context menu that can be used to check and uncheck stats to toggle their visibility.
  • Ability to copy stats by clicking on them.
  • More stats.

Implementation Details

  • Add a new CellSelectionStats component that displays the count, sum, and average of selected cells when two or more are selected.
  • Integrate CellSelectionStats into the DataTableInternal component, position is below the table. Wrap it in the CellSelectionProvider context.
  • Add a getNumericValuesFromSelectedCells utility function in utils.ts to extract numeric values from selected cells, filtering out non-numeric and special columns.

📋 Checklist

  • I have read the contributor guidelines.
  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • Tests have been added for the changes made.
  • Documentation has been updated where applicable, including docstrings for API changes.
  • Pull request title is a good summary of the changes - it will be used in the release notes.

Use selectedCellsAtom to get size of cell selection and display.
Accordingly reorder components such that CellSelectionProvider's scope covers new CellSelectionStats component for it to use the selectedCellsAtom.
@vercel
Copy link

vercel bot commented Feb 16, 2026

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

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Feb 16, 2026 9:28am

Request Review

Add a new test-utils.ts exporting shared mock helpers (createMockCell, createMockColumn, createMockRow, createMockTable, createSelectedCell) and update utils.test.ts to import and use those helpers.
CellSelectionStats counts checkbox column on the left indicating whether a row is selected. This is counter-intuitive. Introduce utility to count all cells excluding the checkbox column.
@andrewsoonqn andrewsoonqn marked this pull request as ready for review February 16, 2026 06:58
@andrewsoonqn andrewsoonqn requested a review from manzt as a code owner February 16, 2026 06:58
Copilot AI review requested due to automatic review settings February 16, 2026 06:58
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 adds Excel-like summary statistics (Count, Sum, Average) to the DataTable component that appear when users select two or more cells. The feature filters numeric values intelligently, excluding non-numeric data from Sum and Average calculations while including all data cells in the Count. The statistics display is positioned below the table and only appears when multiple cells are selected.

Changes:

  • Added getNumericValuesFromSelectedCells and countDataCellsInSelection utility functions to extract and count cell data
  • Created CellSelectionStats component to display Count, Sum, and Average statistics
  • Moved CellSelectionProvider to wrap both the table and the new stats component, enabling state sharing

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
frontend/src/components/data-table/range-focus/utils.ts Added utility functions to count selected cells and extract numeric values, filtering out checkbox columns and non-numeric data
frontend/src/components/data-table/range-focus/cell-selection-stats.tsx New component displaying statistics (Count, Sum, Average) for selected cells with 8 decimal place rounding
frontend/src/components/data-table/range-focus/tests/utils.test.ts Added comprehensive tests for new utility functions and refactored existing test helpers into test-utils.ts
frontend/src/components/data-table/range-focus/tests/test-utils.ts Extracted reusable mock helper functions (createMockCell, createMockRow, createMockTable) for test consistency
frontend/src/components/data-table/range-focus/tests/cell-selection-stats.test.tsx Added thorough tests covering various scenarios: numeric/non-numeric values, rounding, checkbox exclusion, and edge cases
frontend/src/components/data-table/data-table.tsx Repositioned CellSelectionProvider to wrap both table and stats component, added CellSelectionStats below the table

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

Excel-like metrics with data table selection

1 participant