NumberFormater DataTable

Hello everybody,

i am trying to format a number in a cell of a DataTable.
But I would like to use it as a point separator instead of a comma as you use it
for example in Italy.
Also I would like to indicate negative numbers with a red color.
I have not found any solution.
Do you have any suggestions?
A greeting
Mauro

You need a cell formatter: https://docs.bokeh.org/en/latest/docs/reference/models/widgets.tables.html#bokeh.models.widgets.tables.CellFormatter

Check some examples here: https://stackoverflow.com/questions/50996875/how-to-color-rows-and-or-cells-in-a-bokeh-datatable

Thanks YOU for the “instant” replay.

Is two day that I am studing and testing thie examples
[https://stackoverflow.com/questions/50996875/how-to-color-rows-and-or-cells-in-a-bokeh-datatable](https://stackoverflow.com/questions/50996875/how-to-color-rows-and-or-cells-in-a-bokeh-datatable)

But I do not undertand how to have this two things toghether:

if I wish to have togheter this option
formatter1=NumberFormatter(format='0,0.00',
                text_align='right',language='it')
and

formatter2="""
<p style="text-align:right;color:<%=
    (function colorfromint(){
        if(colonna2 < 0){return('red')}
        else{return('black')}
        }()) %>;">
    <%= value %>
    </p>
"""

I can use only one at time, but I need that work togheter like

“excel formatting”

Can You help me?

Kind regards

Mauro
from bokeh.io import show
from bokeh.models import DataTable, TableColumn, ColumnDataSource, HTMLTemplateFormatter

# Note that the result of `toLocaleString()` depends on your locate
# so it will return different results for different users.
# If you REALLY need dots as thousands separates for every user
# regardless of locale, you can just format the value yourself
# however you see fit using JavaScript - there's plenty of examples online.
template = """\
<div style="background:<%= value < 0 ? 'red' : 'initial'%>;">
<%= value ? value.toLocaleString() : value %>
</div>"""
t = DataTable(columns=[TableColumn(title='X', field='x', formatter=HTMLTemplateFormatter(template=template))],
              source=ColumnDataSource(data=dict(x=[-1.5, 0, 1.5])))

show(t)

Thanks
now all work very fine.

Very Very thanks YOU

Kind regards

Mauro
1 Like