Qlik Community

Qlik Sense Integration, Extensions, & APIs

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

Announcements
If you are a Qlik Insight Bot user, join this collaborative group: JOIN GROUP
Highlighted
New Contributor II

General function to set selection state of another app for mashups

Trying to write a general function to set the selection state in another app when writing mashups.

	var stateListener = function(theApp) {	 	
	theApp.clearAll();
    	var selFields = this.selections;
		
		if (selFields!=null){
		$.each(selFields, function(key, value) {
			var valArray=[];
			$.each(value.selectedValues, function(key,value){
				valArray.push(value.qName);
			})
			theApp.field(value.fieldName).selectValues(valArray, true, true);
		});
		}		
  	};

 

So trying to use it like this:

var selState = app.selectionState( );    //get state of app

selState.OnData.bind( stateListener, app1 );    //bind to function with argument of app1 to set it's state

But it's not calling the listener. 

Ideas appreciated!

 

1 Solution

Accepted Solutions
Highlighted
New Contributor II

Re: General function to set selection state of another app for mashups

Found a work-around but not that happy with it.  Instead of an argument I set a global scope var to the application:

	var theApp;

	function stateListener() {	 	
		theApp.clearAll();
		var selFields = this.selections;

		if (selFields!=null){
		$.each(selFields, function(key, value) {
			var valArray=[];
			$.each(value.selectedValues, function(key,value){
				valArray.push(value.qName);
			})
			theApp.field(value.fieldName).selectValues(valArray, true, true);
		});
		}		
	}

and use the function like:

var selState = app.selectionState( ); //get state of app
theApp = app1; //set global to app1
selState.OnData.bind( stateListener ); //bind to function

View solution in original post

1 Reply
Highlighted
New Contributor II

Re: General function to set selection state of another app for mashups

Found a work-around but not that happy with it.  Instead of an argument I set a global scope var to the application:

	var theApp;

	function stateListener() {	 	
		theApp.clearAll();
		var selFields = this.selections;

		if (selFields!=null){
		$.each(selFields, function(key, value) {
			var valArray=[];
			$.each(value.selectedValues, function(key,value){
				valArray.push(value.qName);
			})
			theApp.field(value.fieldName).selectValues(valArray, true, true);
		});
		}		
	}

and use the function like:

var selState = app.selectionState( ); //get state of app
theApp = app1; //set global to app1
selState.OnData.bind( stateListener ); //bind to function

View solution in original post