How to access time-picker from/to within a text-panel and jQuery

I want to realize a simple extension embedded within a HTML-Text panel using JQuery.

As a real newbie newbie I would like to know how I could fetch the current time-picker values ‘from’ and ‘to’ by using jQuery or pure Javascript.

Is it possible to access those information from within a Text-Panel?
Or do I need to develop a plugin to get access to these elements?

Hi,

You can access variables from a text panel for example. Built-in variables may help you? There are an open feature request that you may upvote if interested. Otherwise I guess you have to build your own plugin.

Marcus

You can fetch the current timeRange values from the DOM by using (the already available) angular.

<script type="text/javascript">
var timeRange = angular.element('grafana-app').injector().get('timeSrv').timeRange();
var temp_date_from = new Date(timeRange.from);
var temp_date_to = new Date(timeRange.to);
// Do what you want with the data
</script>
1 Like