Dashboards & Visualizations

Use a CSS button to hide splunk panels

architkhanna
Path Finder

I have a button on a panel X of a dashboard which clears filters/tokens on all other panels (A,B,C) in same dashboard.
I want to use the same button to hide panels(A,B,C) all together and visible once I click on any value of the same panel(X)

Any help would be appreciated.

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@architkhanna

Can you please try this?

<dashboard script="myJS.js">
  <label>Click Button</label>
  <row>
    <panel>
      <title>X</title>
      <html>
        <input id="btn" type="button" value="Hide"/>
      </html>
    </panel>
  </row>
  <row>
    <panel depends="$tknA$">
      <table>
        <title>A</title>
        <search>
          <query>| stats count</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
      </table>
    </panel>
    <panel depends="$tknB$">
      <table>
        <title>B</title>
        <search>
          <query>| stats count</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
      </table>
    </panel>
    <panel depends="$tknC$">
      <table>
        <title>C</title>
        <search>
          <query>| stats count</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
      </table>
    </panel>
  </row>
</dashboard>

myJS.js

require([
        "splunkjs/mvc",
        "splunkjs/mvc/simplexml/ready!"
    ], function (
        mvc) {
    var defaultTokenModel = mvc.Components.get("default");
    var submittedTokenModel = mvc.Components.get("submitted");
    var flag=true;

    $("#btn").on("click", function () {
         console.log("lllllllll");
        if(flag)
        {
            defaultTokenModel.set("tknA", "Hi");
            defaultTokenModel.set("tknB", "Hi");
            defaultTokenModel.set("tknC", "Hi");
            submittedTokenModel.set("tknA", "Hi");
            submittedTokenModel.set("tknB", "Hi");
            submittedTokenModel.set("tknC", "Hi");
            flag = false;
        }
        else {
            defaultTokenModel.unset("tknA");
            defaultTokenModel.unset("tknB");
            defaultTokenModel.unset("tknC");
            submittedTokenModel.unset("tknA");
            submittedTokenModel.unset("tknB");
            submittedTokenModel.unset("tknC");

            flag = true;
        }
        submittedTokenModel.set(defaultTokenModel.toJSON());
        return false;
    });

});
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...