Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
hacr
Creator
Creator

Selection API and Buttons?

Hi all

I'm trying to use the Selection API to extract the current selected filter values, by adding a button to a mashup.

Using the example code from https://help.qlik.com/en-US/sense-developer/September2017/Subsystems/APIs/Content/CapabilityAPIs/Sel...

require(["js/qlik"], function(qlik) { //open apps -- inserted here --  

var app = qlik.openApp('c31e2aba-3b46-4b13-8b87-c5c2514dea1d', config); 

var selState = app.selectionState( );

var listener = function() { alert('Back count:' + selState.backCount); selState.OnData.unbind( listener ); }; selState.OnData.bind( listener );


I put it into a button and everything works fine on the first click. If i select value A, B, C in a filter and press, the desired values are returned. If i make a new selection, and press the button, nothing happens until i make another selection in the filter.


$('.export_selections').on('click', function () {  })


I assume it's something with the bind/unbind listener? It's probably a simple problem, but can't figure out where to look.

1 Solution

Accepted Solutions
ErikWetterberg

Hi,

Perhaps I don't relly understand your use case. The way Qlik Sense works is that you automatically get notified every time selection state changes. Of course you don't have to show the user the updates every time, but you will get notified.

The alternative is to instead get the data when the user clicks the button, but that would be more complicated, you would need to throw away the created objects (or create a memory leek). Not really anything I would recommend.

Erik Wetterberg

View solution in original post

4 Replies
ErikWetterberg

Hi,

Just remove the unbind call.

Erik Wetterberg

hacr
Creator
Creator
Author

Now it updates everytime I click any value in the filter, but I was interested in only to show me the "selected value" when I press the button. Maybe it's impossible to mix the button and the listener?

ErikWetterberg

Hi,

Perhaps I don't relly understand your use case. The way Qlik Sense works is that you automatically get notified every time selection state changes. Of course you don't have to show the user the updates every time, but you will get notified.

The alternative is to instead get the data when the user clicks the button, but that would be more complicated, you would need to throw away the created objects (or create a memory leek). Not really anything I would recommend.

Erik Wetterberg

hacr
Creator
Creator
Author

Yeah, the purpose of the function is a bit different from what I want to do with it. I made the listener to read the selected parameters and return a string to the URL including the selected dimensions + values. I'll look in the API for other options! Maybe I should find an API to just read the values, and not listen to state change.

Anyway, thank you for your inputs!