hi
i want to create a button switcher here is my code in xml format:
but it dosent work, can you help me to know what is my problem
tanck you
@khanlarloo, as stated by @rjthibod, the example that you are trying to implement is not a valid working example. You would need to use JavaScript to code click()
events of Show
and Hide
buttons to set and unset required token using jQuery and Splunk JS Stack.
Following is a run anywhere example with require Dashboard Simple XML and JavaScript code. PS: I have give Show and Hide HTML buttons ids showButton
and hideButton
respectively to easily access through jQuery selector based on ids. You can create specific classes if you want to apply something similar on several buttons.
<dashboard script="button_click.js">
<label>Button Switcher Example</label>
<row>
<panel>
<title>Example to Show or Hide Details Panel based on respective Button Clicks</title>
<html>
show_details : $show_details$
</html>
</panel>
</row>
<row>
<panel>
<html>
<button id="showButton" class="btn">Show</button>
</html>
<chart>
<search>
<query>index=_internal sourcetype=splunkd log_level!=INFO
| timechart count by log_level</query>
<earliest>-24h@h</earliest>
<latest>now</latest>
</search>
<option name="charting.chart">column</option>
<option name="charting.drilldown">none</option>
<option name="refresh.display">progressbar</option>
</chart>
</panel>
<panel depends="$show_details$">
<html>
<button id="hideButton" class="btn">Hide</button>
</html>
<table>
<search>
<query>index=_internal sourcetype=splunkd log_level!=INFO
| timechart count by log_level</query>
<earliest>-24h@h</earliest>
<latest>now</latest>
</search>
<option name="count">5</option>
</table>
</panel>
</row>
</dashboard>
And place the JavaScript button_click.js
under your Splunk App's static folder i.e. $SPLUNK_HOME$/etc/apps/<YourAppName>/appserver/static
:
require([
"splunkjs/mvc",
"splunkjs/mvc/simplexml/ready!"
], function(
mvc
) {
var defaultTokenModel = mvc.Components.get("default");
var submittedTokenModel = mvc.Components.get("submitted");
$("#showButton").click(function(){
defaultTokenModel.set("show_details","true");
submittedTokenModel.set("show_details","true");
});
$("#hideButton").click(function(){
defaultTokenModel.unset("show_details");
submittedTokenModel.unset("show_details");
});
});
PS: Since this requires static
file i.e. button_click.js
, you might need to restart/refresh/bump Splunk and also clear internet browser cache for the changes to reflect.
If you also want to hide the Show
button, when the Details panel is displayed and toggle back to show when Hide button in Details panel is clicked then you can add rejects
attribute for the html
panel containing Show
button i.e.,
<html rejects="$show_details$">
<button id="showButton" class="btn">Show</button>
</html>