Dashboards & Visualizations

How do I update choices of DropdownView?

bhawkins1
Communicator

The splunk web framework provides a dropdown view component which I populate with choices before rendering:

  var menu = new DropdownView({
    id:              "split_categories_" + idx,
    choices:         opts_to_choices(opts),
    default:         "Usage",
    showClearButton: false,
    el:              $(this)
  }).render();

The documentation:

http://docs.splunk.com/DocumentationStatic/WebFramework/1.0/compref_dropdown.html

Provides info about listening to on-change events, setting choices, and rendering, but doesn't mention anything about changing the choices that appear in the dropdown menu.

If you analyse the structure of the menu object after rendering, you can see that choices are stored inside the options child object. None of the following correctly updates the choices:

  • Setting menu.choices to a new value
  • Setting menu.choices to a new value and re-rendering
  • Setting menu.options.choices to a new value
  • Setting menu.options.choices to a new value and re-rendering

If you take a look at the views source (which I'm not even sure is relevant or not),

https://github.com/splunk/splunk-webframework/blob/master/server/static/splunkjs/compiled/views.js

You might be led to believe that:

  • Setting menu.el.innerHTML = "" might cause menu.render() to work again
  • Calling menu.setItems() on a new object might be the correct way to change choices

Neither of these works either.

So what's the correct way to re-render the view?

1 Solution

bhawkins1
Communicator

The 1.0 reference is outdated. If you manually change the reference URL from 1.0 to 1.2, you'll get the following updated reference:

http://docs.splunk.com/DocumentationStatic/WebFramework/1.2/compref_dropdown.html

Here, you can see that menu.settings.set("choices", []) is the correct way to change the choices in a dropdown view.

Sadly, the default google result finds web framework @ 1.0, and the 1.0 docs don't have any reference to the 1.2 docs.

View solution in original post

bhawkins1
Communicator

The 1.0 reference is outdated. If you manually change the reference URL from 1.0 to 1.2, you'll get the following updated reference:

http://docs.splunk.com/DocumentationStatic/WebFramework/1.2/compref_dropdown.html

Here, you can see that menu.settings.set("choices", []) is the correct way to change the choices in a dropdown view.

Sadly, the default google result finds web framework @ 1.0, and the 1.0 docs don't have any reference to the 1.2 docs.

Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...