Widget Display Not Updating On Dashboard Filter Change
Hi all,
So I am running the following script on my widget (using 'edit script') in order to grab the date of the maximum dollars for a year using a different bar chart widget on the dashboard, and display that date (along with the $ amount) on an indicator widget
var dateStr = '';
widget.on('processresult', function(e,v) {
var results = widget.queryResult;
console.log(results);
var maxNum = results.value.data;
var replaceNum = results.secondary.data;
//var dateStr = '';
console.log(results);
var widg = dashboard.widgets.get('6633bbf55a7e230040304e8c');
var widgResult = widg.rawQueryResult.values;
console.log(widgResult);
$.each(widgResult, function(index, item) {
let date = item[0].data;
let amt = item[1].data;
if (amt === maxNum) {
dateStr = date;
};
});
//results.secondary.data = dateStr.substring(0, 10);
//results.secondary.text = dateStr.substring(0,10);
});
widget.on('render', function(se, ev) {
var results = widget.queryResult;
results.secondary.data = dateStr.substring(0, 10);
results.secondary.text = dateStr.substring(0,10);
});
widget.refresh();
This works, and gets me the proper date. However, when I open the dashboard (/refresh the page), or change filters, the displayed date doesn't update, and only updates when I do something like changing the widget's width on the dashboard manually, as though I am manually refreshing the widget's render state or something.
Can anyone help me with a solution so that the widget properly displays the info without having to manually change its size to refresh the display?
Thanks in advance
Hello turtleData123
I am not an expert on this, however I think it has to do with when this script is triggered (the widget event). If you change the event, the script will be triggered at a different moment. More on the events can be found here:
https://sisense.dev/guides/customJs/jsApiRef/widgetClass/
You could also try to use a dashboard-event
Hamza