Qlik Community

Qlik Sense Integration, Extensions, & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

hacr-sds
Contributor

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.

Tags (2)
1 Solution

Accepted Solutions
erik_wetterberg
Honored Contributor

Re: Selection API and Buttons?

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

Erik Wetterberg
https://extendingqlik.upper88.com/
4 Replies
erik_wetterberg
Honored Contributor

Re: Selection API and Buttons?

Hi,

Just remove the unbind call.

Erik Wetterberg

Erik Wetterberg
https://extendingqlik.upper88.com/
hacr-sds
Contributor

Re: Selection API and Buttons?

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?

erik_wetterberg
Honored Contributor

Re: Selection API and Buttons?

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

Erik Wetterberg
https://extendingqlik.upper88.com/
hacr-sds
Contributor

Re: Selection API and Buttons?

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!

Community Browser