I’m working on Grafana and using the Dynamic Text plugin for some custom Datetime picker buttons and links. If I create the buttons as anchor elements with an href that references the same dashboard/URL with different time params (now and to), it works great and doesn’t do a full page refresh. I’d like to include other links though, so I’ve changed the anchors to buttons and added an onclick function. In the onclick function, I can change the URL to have the correct URL params using history.pushState, but the dashboard does not respond to the changed URL. If I use window.location.href = newURL, it will do a full page refresh.
HTML content rendered from Grafana Panel:
{{#each data}}
<button onclick="setDateParams('{{time_from}}','{{time_to}}')">{{button_text}}</button>
{{/each}}
Javascript:
setDateParams = (time_from, time_to) => {
let url = new URL(window.location);
url.searchParams.set('from', time_from);
url.searchParams.set('to', time_to);
history.pushState(null, null, url);
return;
}