How to hide a widget?
I'm trying to hide a widget and see that in the widgetManifest Class there is a hideNoResults but I don't see how you're supposed to set it. How would I go about doing this?
-
Hi Rourke,
I used a dashboard script to hide widgets when there's no data.
For example, id 1111 is a widget showing a customer activity (it's on a drill dashboard, so exactly one customer is filtered).
In my case, if there are no sales the widget will show no data (and not 0).I also have a text widget 0000 with text "No activity found for customer".
Then, I have several other widgets about the customer activity (2222, 3333, 4444...)
The following script will hide all the widgets but the text widget in case there is no customer activity.
So the viewer will see a clear label "No activity found for customer" and not just a bunch of empty widgets.
dashboard.on('widgetrender',function(se,ev){
if (ev.widget.oid =="1111")
{
console.log(ev.widget);
var r = ev.widget.$noResults;
if (r)
{
console.log('no images usage');
$('widget[widgetid="2222"]').hide();
$('widget[widgetid="3333"]').hide();
$('widget[widgetid="4444"]').hide();
$('widget[widgetid="0000"]').hide();
} else { $('widget[widgetid="0000"]').hide(); }}
-
Hey, not sure about using the widgetManifestClass, but I did come up with a pretty generic way to hide widgets with no results. Just paste this into the widget script:
widget.on('refreshed', function(w, args) {
if (w.rawQueryResult.isEmpty == true) {
$('widget[widgetid="' + w.oid + '"]').hide();
}
}); -
Would there be anyway to write this so, that when I change the a filter and the condition of the widget changes, it would display that widget with out a full manual page refresh? Also, since I'm here, when I use this code, it make all the widgets that I have IDs for disappear, when really I just want the ones that have the 'No Results' image in them to disappear. Any help on this one?
dashboard.on('widgetrender',function(se,ev){
console.log(ev.widget);
var r = ev.widget.$noResults;
if (r) {
console.log('no images usage');
//Multi Check ID
$('widget[widgetid="5b84036bf6f6202ac433b463"]').hide();
//Single Check ID
$('widget[widgetid="5b86cf64b3b22602786a0e1c"]').hide();
//Attribute Checks
$('widget[widgetid="5b86d53bb3b22602786a0f76"]').hide();
$('widget[widgetid="5b84036bf6f6202ac433b464"]').hide();
$('widget[widgetid="5b881eb41af3ac14d058d684"]').hide();
} else {
$('widget[widgetid="5b84036bf6f6202ac433b463"]').show();
//Single Check ID
$('widget[widgetid="5b86cf64b3b22602786a0e1c"]').show();
//Attribute Checks
$('widget[widgetid="5b86d53bb3b22602786a0f76"]').show();
//Comments
$('widget[widgetid="5b84036bf6f6202ac433b464"]').show();
//Second Comments
$('widget[widgetid="5b881eb41af3ac14d058d684"]').show();
}
}) -
Also, I've tried this at a widget level too. and had good success just could get the widget to come back till a hard refresh.
widget.on('ready', function(send,ev,w, args) {
var $container = $('[widgetid="5b86d53bb3b22602786a0f76"]');
var r = ev.widget.$noResults;
if (r)
{$container.parentsUntil('.dashboard-layout-subcell-host').last().parent().hide();}
else { $('widget[widgetid="5b86d53bb3b22602786a0f76"]')};
}); -
There are many instances that I would like to be able to hide widgets conditionally, and using a combination of these scripts meets those needs. However, the webpage/dashboard still budgets space for the hidden widgets and that white space also shows up in the PDF exports of the dashboard.
Is there any way to have the dashboard re-evaluate the height of the page after hiding the widgets, and/or have the PDF export omit those hidden widgets when sizing?
-
I was able to make the widget disappear and reappear using Delsaran's code with modification to the .hide().
widget.on('ready', function(send,ev,w, args) {
var $container = $('[widgetid="5c9bd39167f57430dc665101"]');
var r = ev.widget.$noResults;if (r)
{$container.parentsUntil('.dashboard-layout-subcell-host').last().parent().css("visibility", "hidden");}
else{$container.parentsUntil('.dashboard-layout-subcell-host').last().parent().css("visibility", "visible");}
});
Please sign in to leave a comment.
Comments
8 comments