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

You need a cell formatter:

Check some examples here:

Thanks YOU for the “instant” replay.

Is two day that I am studing and testing thie examples

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

if I wish to have togheter this option

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

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

“excel formatting”

Can You help me?

Kind regards

from 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 %>
t = DataTable(columns=[TableColumn(title='X', field='x', formatter=HTMLTemplateFormatter(template=template))],
              source=ColumnDataSource(data=dict(x=[-1.5, 0, 1.5])))


now all work very fine.

Very Very thanks YOU

Kind regards

1 Like