Selecting options in selectMenu

531 views
Skip to first unread message

Dmitriy Meshkov

unread,
Jun 9, 2016, 4:14:16 AM6/9/16
to dc-js user group
Hi, guys!

I'm using the development build of dcjs (btw, it's awesome!) to have selectMenu inside. And I need to change the options of select element in js. I'm doing it in a usual way:
$('#select-scheme > select > option')[3].selected = true

and getting the selected value without any problems:
$('#select-scheme > select').val() // ["value1"]

But the selected value (values - in cases of using multiple selectMenu) is not applied to the filtering, so no redraw after my selection of options. Requesting the list of filters brings me the empty result:
selectMenu.filters() // []

Selecting the options manually (keyboards or mouse) leads to expected result - the charts are being redrawn normally.
What am I doing wrong? Should I use some method to apply the selected filters?


Thank you!

Dmitriy Meshkov

unread,
Jun 9, 2016, 5:07:04 AM6/9/16
to dc-js user group
Little update.

Triggering manually the "change" event after changing the "selected" property of any option inside select also brings no result.
$('#select-scheme > select > option')[3].selected = true
$('#select-scheme > select').change() // no effect

Gordon Woodhull

unread,
Jun 9, 2016, 8:00:44 AM6/9/16
to dc.js user group
Hi Dmitriy,

Just as with the other charts, the display is driven from the data and changing the display won't change the data. 

You should call the menu.filter() or menu.replaceFilter() function to set the values, and then call menu.redrawGroup() to redraw the widget and all charts which rely on its filter.

In your case, this will look something like

selectMenu
    .replaceFilter([["value1", "value2", "value3"]])
    .redrawGroup()

Note the array containing a single array. It is a quirky interface.

The documentation for chart.filter() was incomplete and out-of-date, so I've just rewritten it. chart.replaceFilter() was not previously documented, and it is usually what people want, since filter on its own always toggles the values.


(The filter function has gotten rather complex over the years! I'd appreciate if local experts could give this a thorough review as we prepare for 2.0.)

Cheers,
Gordon


--
You received this message because you are subscribed to the Google Groups "dc-js user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dc-js-user-gro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dc-js-user-group/567a3fe1-8c5d-4bae-8948-41036b85602f%40googlegroups.com.

Dmitriy Meshkov

unread,
Jun 21, 2016, 4:10:42 AM6/21/16
to dc-js user group
Thank you, Gordon, and sorry for a late response!
That's the methods I've used to achieve my goal! Thank you for your job!
Reply all
Reply to author
Forward
0 new messages