Click Script gives error and not updating variables
Opened this issue · 6 comments
I faced the same issue, and found a solution after poking around in the code:
The function executed when you click gets 3 arguments, as you can see here:
var f = new Function('data', 'getLocationSrv', 'getTemplateSrv', this.props.options.onclick);
f(data, getLocationSrv, getTemplateSrv);
data
, getLocationSrv
and getTemplateSrv
.
And from the Grafana Docs, you can find how to update a variable from the LocationSrv
.
So TL;DR, simply use:
getLocationSrv().update({
query: {
'var-service': 'billing',
},
partial: true,
replace: true,
});
This is a good workaround for user-defined variables but seemingly cannot be used to control the timerange of the main window by updating 'from' and 'to' in the query map, as was possible in Grafana < 8.0 with the windowUpdateVariables option. Does anyone have a solution for updating these?
Hum.. Not even with the __from
and __to
notations? (with the underscores)
Apologies. User error. I had inadvertently pinned the time range of a panel. The standard from
and to
work as expected with this workaround. Thanks again!
Hello,
Trying to get a minimal example to work but having a hard time ...
I'm using Grafana 8.4.6 & Plotly panel 0.5.0.
Using the example provided here as a starting point, I'm trying to get the click script to update the 'project' dashboard variable. With the click script that comes with this example panel, the console reports the same error as @KengHzou was seeing. Changing it to (as suggested by @z0rzi)
getLocationSrv().update({
query: {
'var-service': 'billing',
},
partial: true,
replace: true,
});
results in another error (Uncaught ReferenceError: getLocationSrv is not defined
).
Any help on how this should be modified would be greatly appreciated!
So as I understand, the window.updateVariables()
is deprecated? Therefore the default value that is populated in the click data field should be updated?