How to use column format specifier in DataTable?

Hi!

For some reason, I cannot get DataTable to format numeric values correctly. I wonder what I’m doing wrong, could anyone help?

Here’s a stripped down example of my data table:

dash_table.DataTable(
    id="datatable-metrics",
    columns=[
        {
            "name": "Site",
            "id": "site",
        },
        {
            "name": "Avg power",
            "id": "avg_power",
            "format": {
                "specifier": ".1f",
            },
        },
    ]
)

However, avg power gets formatted without any rounding/clipping of decimals so it can show 8 decimals or even more instead of just one. Any ideas why my specifier doesn’t work?

Hi @jluttine, and welcome to the Dash community!

The column needs to be defined as numeric for the formatting to work.

Try adding: "type": "numeric", to the avg power column

1 Like

@AnnMarieW Thanks, that did it! :blush: :+1:

1 Like