I am able to render an AG-grid by following the example code laid out on the JustPy website. However when it comes to formatting cells or columns the AG-grid documentation shows using valueFormatter and arrow functions. For example to format a number to 2 decimals in AG-grid would like like:
valueFormatter: params => params.data.number.toFixed(2)
I'm am struggling to see how I could translate this some kind of string to pass to to the valueFormatter property of the JustPy grid component. In the code snippet below the styling works for cellClass and cellClassRules but the formatting line does not work and many attempts at different strings are all failing. If anyone has gotten this to work and can share any example to get me going it would be greatly appreciated.
update: Thank you @thirtydot that recommendation sent me in the right direction. But I am still tripping up because getDataPath is a single option to evalutate but here I am looking to evaluate a function that is under valueFormatter which it itself is a property of columnDefs. Then also there are multiple fields that each have their own columndefs and valueformatter properties. So am I to evaluate ALL 'ColumnDefs', or evaluate 'valueFormatter'? Can I do it generically like below or do I need to evaluate each one (i.e. evaluate['columnDefs[9]'])? If anyone has had success with this please let me know. I feel like I am much closer than I started but still far away. The code below produces an ag-grid with the correct conditional formatting but the valueformatter is not evaluating and thus not returning formatted numbers.
def grid_test1():
wp = jp.WebPage()
grid = ooi.jp.ag_grid(a=wp) # a=wp adds the grid to WebPage wp
grid.theme = "ag-theme-balham-dark"
grid.options.columnDefs[0].cellClass = ['text-white', 'bg-blue-500', 'hover:bg-blue-200']
grid.options.columnDefs[9].valueFormatter = {'''function(params) { '$' + formatNumber(params.value); }'''}
grid.options.columnDefs[15].valueFormatter = {'''function(params) { params.data.number.toFixed(2); }'''}
for col_def in grid.options.columnDefs[1:]:
col_def.cellClassRules = {
'font-bold': 'x < 20',
'bg-red-300': 'x < 20',
'bg-yellow-300': 'x >= 20 && x < 50',
'bg-green-300': 'x >= 50'
}
grid.evaluate = ['valueFormatter']
return wp