In the following example app, only the cell contents of col1 are correctly formatted to three decimal places. The AG Grid docs list valueFormatter as a possible key of column types though. Removing the {"function": ...} layer does not help. Am I doing something wrong?
import numpy as np
import pandas as pd
from dash import Dash
from dash_ag_grid import AgGrid
columnDefs = [
{
"field": "col1",
"type": "rightAligned",
"valueFormatter": {"function": "d3.format('.3f')(params.value)"},
},
{
"field": "col2",
"type": "float",
},
]
dashGridOptions = {
"columnTypes": {
"float": {
"cellClass": "ag-right-aligned-cell",
"headerClass": "ag-right-aligned-header",
"valueFormatter": {"function": "d3.format('.3f')(params.value)"},
}
}
}
df = pd.DataFrame(
{
"col1": np.random.rand(5),
"col2": np.random.rand(5),
}
)
grid = AgGrid(
columnDefs=columnDefs,
dashGridOptions=dashGridOptions,
rowData=df.to_dict("records"),
)
app = Dash()
app.layout = [grid]
if __name__ == "__main__":
app.run(debug=True)