Splunk Search

How to create drop-down search inputs in HTML to filter my data?

pmardo
New Member

I want to have search inputs/drop downs that can filter out my data similar to this question:
https://answers.splunk.com/answers/148500/how-to-set-up-three-dynamic-dropdowns-on-dashboard-in-simp...

Is there a way to do this in HTML?

Tags (3)
0 Karma
1 Solution

renjith_nair
SplunkTrust
SplunkTrust

Yes it's possible in HTML. Easiest way is to create it in xml and convert it to html

Here is an example of adding a dropdown to existing html dashboard.

Add div tags for the element

<div class="fieldset">
        <div class="input input-dropdown" id="input1">
            <label>MyLabel</label>
        </div>
    </div>

Add a search to populate the drop down. You can skip it if you have only static values

            var search2 = new SearchManager({
            "id": "search2",
            "latest_time": "now",
            "earliest_time": "-24h@h",
            "cancelOnUnload": true,
            "status_buckets": 0,
            "search": "index=*|stats count by sourcetype",
            "app": utils.getCurrentApp(),
            "auto_cancel": 90,
            "preview": true,
            "runWhenTimeIsUndefined": false
        }, {tokens: true});

Create the element and add a function to handle dropdown change. Static values can be added in choices

         var input1 = new DropdownInput({
            "id": "input1",
            "choices": [
                {"value": "*", "label": "All"}
            ],
            "labelField": "sourcetype",
            "selectFirstChoice": false,
            "default": "*",
            "valueField": "sourcetype",
            "showClearButton": true,
            "searchWhenChanged": true,
            "value": "$form.srctype$",
            "managerid": "search2",
            "el": $('#input1')
        }, {tokens: true}).render();

        input1.on("change", function(newValue) {
            FormUtils.handleValueChange(input1);
        });

If you don't have dynamic values managerid can be removed which has a reference to the previously created search .

Please refer here for more details : http://dev.splunk.com/view/webframework-htmldashboards/SP-CAAAETK

Happy Splunking!

View solution in original post

renjith_nair
SplunkTrust
SplunkTrust

Yes it's possible in HTML. Easiest way is to create it in xml and convert it to html

Here is an example of adding a dropdown to existing html dashboard.

Add div tags for the element

<div class="fieldset">
        <div class="input input-dropdown" id="input1">
            <label>MyLabel</label>
        </div>
    </div>

Add a search to populate the drop down. You can skip it if you have only static values

            var search2 = new SearchManager({
            "id": "search2",
            "latest_time": "now",
            "earliest_time": "-24h@h",
            "cancelOnUnload": true,
            "status_buckets": 0,
            "search": "index=*|stats count by sourcetype",
            "app": utils.getCurrentApp(),
            "auto_cancel": 90,
            "preview": true,
            "runWhenTimeIsUndefined": false
        }, {tokens: true});

Create the element and add a function to handle dropdown change. Static values can be added in choices

         var input1 = new DropdownInput({
            "id": "input1",
            "choices": [
                {"value": "*", "label": "All"}
            ],
            "labelField": "sourcetype",
            "selectFirstChoice": false,
            "default": "*",
            "valueField": "sourcetype",
            "showClearButton": true,
            "searchWhenChanged": true,
            "value": "$form.srctype$",
            "managerid": "search2",
            "el": $('#input1')
        }, {tokens: true}).render();

        input1.on("change", function(newValue) {
            FormUtils.handleValueChange(input1);
        });

If you don't have dynamic values managerid can be removed which has a reference to the previously created search .

Please refer here for more details : http://dev.splunk.com/view/webframework-htmldashboards/SP-CAAAETK

Happy Splunking!

pmardo
New Member

I can't seem to get it to filter my data. The drop down lists all the correct data, but I can't seem to filter out information.

For example:

Sample Stat Table: NAME, ID, FavoriteColor

Data/Inputs in the collection:
Abby, 01, Blue
Bill, 02, Green
Chris, 03, Purple

My dropdown is searching based on the ID. So when I click my drop down, it lists: 01,02,03. However, if I select 03, it does nothing. Same with all other IDs. Is there something I'm missing?

I want to be able to list all data based on the ID, even if there are duplicates.

For example:
Abby, 01, Blue
Bill, 02, Green
Chris, 03, Purple
Daniella, 03, Black

If I search on all IDs with 03, I'll get:
Chris, 03, Purple
Daniella, 03, Black

0 Karma
Get Updates on the Splunk Community!

NEW! Log Views in Splunk Observability Dashboards Gives Context From a Single Page

Today, Splunk Observability releases log views, a new feature for users to add their logs data from Splunk Log ...

Last Chance to Submit Your Paper For BSides Splunk - Deadline is August 12th!

Hello everyone! Don't wait to submit - The deadline is August 12th! We have truly missed the community so ...

Ready, Set, SOAR: How Utility Apps Can Up Level Your Playbooks!

 WATCH NOW Powering your capabilities has never been so easy with ready-made Splunk® SOAR Utility Apps. Parse ...