Black Lives Matter. Please consider donating to Black Girls Code today.

Datatable - cells format like percent (%) ('format' in style_data_conditional doesn't work)

Hi!

I need to add percent symbol in one row of datatable.
How can i add ‘format’: FormatTemplate.percentage(1) in the next code

style_data_conditional=[
                    {
                        'if': {
                            'row_index': 3,
                            'column_id': i,
                            'filter_query': '{' + str(i) + '} > 100'
                        },
                        'backgroundColor': '#99EE6B'
                    } for i in col_list
                ] + [
                    {
                        'if': {
                            'row_index': 3,
                            'column_id': i,
                            'filter_query': '{' + str(i) + '} < 100',
                            },
                            'backgroundColor': '#FF7373',
                    } for i in col_list
                ]

I tried to specify the format as in this example:

style_cell_conditional=[
                    {
                        'if': {'row_index': 3},
                        'textAlign': 'left',
                        'format': "{:.2f}%",
                    }
                ]

but it doesn’t work.

Help please.

So the next code doesn't work either
style_cell_conditional=[
                    {
                        'if': {'row_index': 3},
                        'type': 'numeric',
                        'format': FormatTemplate.percentage(1).sign(Sign.positive)
                    }
                ]

The style_cell_conditionalonly allows you to change the style of the cell (color, font size, etc), not it’s contents. In order to add the % symbol to the table, this must be done to the data itself.

@flyingcujo

I tried to do so -

                style_data_conditional=[
                    {
                        'if': {
                            'row_index': 3,
                            'column_id': i,
                            'filter_query': '{' + str(i) + '} > 100'
                            },
                        'backgroundColor': '#99EE6B',
                        'type': 'numeric',
                        'format': FormatTemplate.percentage(1)
                    } for i in col_list
                ]

and it also doesn’t work

@Masya, Did you solve this?

format is a nested property of individual columns inside the prop columns and as such, can only be set on a per-column basis. It is currently not possible to apply a format (conditional or otherwise) through style_data or style_data_conditional.