Dash Ag Grid value getter current date

Hi folks, I’m struggling with a value getter. Is working with dates supported? both
valueGetter= {“function”: “Date();”} and valueGetter= {“function”: “new Date();”}, return nothing, and no error is thrown. I can use d3.isoParse(params.my_column), but I actually need to compute a number of days from today till that specific date. But d3 does not seem to have a function to return current date, so I’m stuck.

Hello @fingoldo,

To do something like this, you’ll need to make a function in the clientside namespace of dashAgGridFunctions, we dont allow all default functions from the browser as this could lead to security issues. Thus, you need to create the function and then pass the whole thing to the function.

1 Like

Thank you so much! I can confirm that this works:

In dashAgGridComponentFunctions.js:

var dagfuncs = window.dashAgGridFunctions = window.dashAgGridFunctions || {};

dagfuncs.DaysTillDate = function (value) {
return Math.round((new Date(value) - Date.now()) / (24 * 60 * 60 * 1000));

later in columnsDef:

valueGetter= {“function”: “DaysTillDate(params.data.sales_from)”},

However, it seems like Dash documentation could be improved to include information about this limitation. After reading Value Getters | Dash for Python Documentation | Plotly it is not clear that not all javascript functions are allowed. Can someone add this valuable information to the docs, please?

1 Like

By chance, did you take a look here?

My bad, read breafly a while ago, but totally forgotten )) question withdrawn. Thanks!

1 Like