Dashboards & Visualizations

xml code to add custom button in dashboard

ashwinipatil007
New Member

hi,

I want to add a custom button in the dashboard for the following data

can someone please help me on how to proceed with these as if new to this?

EXAMPLE DATA:
macro
micro
alpa

When I click on macro button it should show me the following result:

RESULT macro:
atom
electron

similarly when I click on micro button it should give me only micro result and not macro:
RESULT micro:
neutron
proton

0 Karma

DataOrg
Builder

@ashwinipatil007
try this

 <input type="link" id="submit_button" token="Submit" searchWhenChanged="true" depends="SERVERS">
            <label></label>
            <choice value="submit">Submit</choice>

          </input>

Style

<style>
#submit_button label {
              color: #fff701;
              font-size: 12px;
          }
</style>
0 Karma

manjunathmeti
Champion

You can use inbuilt inputs like dropdown or radio buttons.

<form>
  <label>Label</label>
  <fieldset submitButton="true">
    <input type="radio" token="field1">
      <label>Select option:</label>
      <choice value="macro">macro</choice>
      <choice value="micro">micro</choice>
      <choice value="alpa">alpa</choice>
      <default>macro</default>
    </input>
  </fieldset>
  <row>
    <panel depends="$field1$">
      <title>Panel 1</title>
      <table>
        <search>
          <query>USE $field1$ in your search query.</query>
        </search>
      </table>
    </panel>
  </row>
</form>
0 Karma

ashwinipatil007
New Member

I actually want to use Onclick button , not the radio or dropdown.
so is there any piece of code which works for on click button?

or if can write it in js or html code kindly let me know

0 Karma

manjunathmeti
Champion

Then you can add button in dashboard using html.

<row>
      <html>
          <button id="macro" class="btn btn-primary">Macro</button>
          <button id="micro" class="btn btn-primary">Micro</button>
      </html>
  </row>

Then in js you can implement onclick.

require([
     "splunkjs/mvc",
     "splunkjs/mvc/simplexml/ready!"
 ], function(mvc) {
     var tokens = mvc.Components.get("default");
  $('#macro').on("click",function(){
         tokens.set("macro", "Macro");
         tokens.unset("micro");
     });
   $('#micro').on("click",function(){
         tokens.set("micro", "Micro");
         tokens.unset("macro");
     });
 });

Sample xml:

<form>
  <init>
    <set token="macro">Macro</set>
    <set token="micro">Micro</set>
  </init>
  <label>Label</label>
  <row>
      <html>
          <button id="macro" class="btn btn-primary">Macro</button>
          <button id="micro" class="btn btn-primary">Micro</button>
      </html>
  </row>
  <row depends="$macro$">
    <panel>
      <title>Panel Macro</title>
    </panel>
  </row>
  <row depends="$micro$">
    <panel>
      <title>Panel Micro</title>
    </panel>
  </row>
</form>
0 Karma

ashwinipatil007
New Member

appreciate for your quick response :)but thehtml code is not working as expected,when I click on macro it is not showing the title ,similary when I click on micro it is not showing the result.
tried with the exact code also which you gave still no luck!
tested the function of js script with an alert it is working fine.but not sure of the html and xml code

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

What Is Splunk? Here’s What You Can Do with Splunk

Hey Splunk Community, we know you know Splunk. You likely leverage its unparalleled ability to ingest, index, ...

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...

Manual Instrumentation with Splunk Observability Cloud: How to Instrument Frontend ...

Although it might seem daunting, as we’ve seen in this series, manual instrumentation can be straightforward ...