Skip to content

[Feature]: Column value formatting for render.DataGrid / render.DataTable #2472

Description

@jeffkeller-einc

Category

Input/Output

Scope

Minor Enhancement

Problem

I'm porting a Shiny app from R to Python, and the one thing I can't reproduce is number formatting in a table. In R I did this:

DT::datatable(dat) |>
  DT::formatCurrency(
    columns = c("Invoice", "MSRP"),
    currency = "$",
    digits = 0
  )

So the grid holds real numbers, but the cells display values like $32,295.

In Python there doesn't seem to be an equivalent. DataGrid takes styles, which is great for CSS, but it only changes how a cell looks, not how the value is rendered.

Solution

What I'd love is a way to attach a display format to a column while the underlying value stays numeric, so sorting and filtering keep working. Something in the spirit of:

render.DataGrid(
    df,
    format={
        "MSRP": "$,.0f",
        "Invoice": "$,.0f",
    }
)

Whatever the API ends up being, the pieces I care about are currency, thousands separators, percentages, and controlling decimal places.

Alternatives (Optional)

The workarounds I can see both give something up:

  • Format the values into strings before handing them to the grid. Now sorting is lexicographic and the numeric range filter turns into a text search, which is worse for the user than the unformatted numbers were.
  • Leave them as raw floats and stuff the units in the column name. Works, but 32295.0 in a table of prices looks unfinished.

Example (Optional)

Impact (Optional)

No response

Contribution? (Optional)

No, just suggesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority: LowLow-impact bug, docs polish, papercut, or unclear low-severity request.ai-triage:doneMarks an issue whose AI triage workflow is complete.enhancementNew feature or requestneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions