Dashboards & Visualizations

How do you populate dropdown via javascript?

bizsplunk
Engager

hi all,

can somebody help with populating a dropdown list via JavaScript? My goal is to pass search results to allow to choose it in dropdown "choices " list.

Thanks in advance.

code is like:

require([
        "splunkjs/mvc",
        "splunkjs/mvc/searchmanager",
        "splunkjs/mvc/dropdownview",
        "splunkjs/mvc/simplexml/ready!"
    ], function(
        mvc,
        SearchManager,
        DropdownView,
    ) {
    var ddsearch = new SearchManager({
            id: "ddsearch2",
            preview: true,
            cache: true,
            search: "| inputlookup earthquakes.csv | table Region | dedup Region | head 6"
        });

        var dropdown1 = new DropdownView({
            id: "dropdown1",
        labelField: "Region",
            valueField: "Region",
            default: "All",
            value: mvc.tokenSafe("$ddtok$"),
            el: $("#dropdown1")
        }).render();
    })
0 Karma

martin_mueller
SplunkTrust
SplunkTrust

SimpleXML can do this out of the box, via the graphical editor. If you like you can then inspect the generated JS code.

http://docs.splunk.com/Documentation/Splunk/7.2.1/Viz/FormEditor#Specify_dynamic_options

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

You can inspect the generated JS code in a SimpleXML dashboard to see how Splunk's doing it.

0 Karma

bizsplunk
Engager

Hi,
the problem is that i`m trying to integrate third-part library and i use js stack and i need to do it via javascript. is there any way?

0 Karma
Get Updates on the Splunk Community!

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...