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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...