How to hide a widget?

Comments

8 comments

  • Avatar
    Tal Admon

    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(); }

    }

    0
    Comment actions Permalink
  • Avatar
    Ian Emmons

    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();
             }
    });

    0
    Comment actions Permalink
  • Avatar
    Delsaran Bigglesworth

    Does this still work in 7.2? I tried both suggestions and neither worked for me...

    0
    Comment actions Permalink
  • Avatar
    Delsaran Bigglesworth

    You're missing a curly bracket in there, I think. And could you explain what ID your inserting into these. Is it the widget ID "5bc09acad0869b294469c620" or the dashboard ID?  Also what the 'else' statement doing?

    0
    Comment actions Permalink
  • Avatar
    Delsaran Bigglesworth

    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();
    }
    })
    0
    Comment actions Permalink
  • Avatar
    Delsaran Bigglesworth

    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"]')};
    });

     

    0
    Comment actions Permalink
  • Avatar
    JJ Chritton (Edited )

    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?

    0
    Comment actions Permalink
  • Avatar
    Chad VanScoy

    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");}
    });

    0
    Comment actions Permalink

Please sign in to leave a comment.