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!

Get the T-shirt to Prove You Survived Splunk University Bootcamp

As if Splunk University, in Las Vegas, in-person, with three days of bootcamps and labs weren’t enough, now ...

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...