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: 
organgrindingmo
Partner - Contributor III
Partner - Contributor III

Change selection within Custom Extention

Hi

TL;DR; How can I make a selection from an Extention or reference a Listbox and use it to make the selection.

I've built a custom pivot table which uses the Product on the x axis, Province on the y axis and a composite key in the cross section. Each cross section cell has a check box which calls a function to select/deselect with the composite key.

I'm having trouble making the actual selection, according to the documentation the only methods available to make a selection from an extension is SelectTextsInColumn(...) and SelectValuesInColumn(...) but I cant use either as the composite key isn't within those columns.

When I used SelectTextsInColumn(...) with the Product or Province name, it works fine but I need to use the composite key.

I've set up a ListBox with the composite keys and I'm trying to get an reference to it and make the selection with SelectTexts(...) but I get and error when I try make the selection.

I've got the following code to test using the GetSelected() function;

window.onRowItemClick = function(box, key) {

    

     // -- code removed for brevity --

     var mydoc = Qv.GetCurrentDocument();

     console.log(mydoc);

     var lb = mydoc.GetObject('LB');

     console.log(lb);

     var selected = lb.Data.GetSelected();           // <--- Object doesn't support property or method 'GetSelected'

     console.log(selected);

When I run the same code within the Firebug extension, the lb.Data.GetSelection() works fine and returns the array of selected items.

firebug.jpg

I'm looking for any way to make the selection with my composite key.

Thanks in advance.

1 Solution

Accepted Solutions
organgrindingmo
Partner - Contributor III
Partner - Contributor III
Author

I have found the solution which is rather simple. You can only do a selection on dimensions within the Extension using SelectTextsInColumn(Column, toggle, recordsToSelect), the Column parameter refers to which dimension you want to select in.

All I had to do was add an extra Composite Key Dimension and then select on that Column.

ie: SelectTextsInColumn(2, true, "compKeyValue"); where the 2 refers to the 3rd item in my dimension array.

0 = product, 1 = province and 2 = compKey

The rest of the post is not part of the solution that I used but was part of the question so I thought I'd post it anyway.

I've also found out why I couldn't use the GetSelected() function on the ListBox. The document.GetObject("ObjectId", callbackFn) uses a callback to return the object. I was calling the GetSelected function on the object reference before it was returned.


Within the callback the this.Data.SelectTexts() function works but it brings other problems, the GetObject() function appends another callback to your object every time a selection is made and it gets an additional one because the Extension has rerendered which also attaches yet another callback. So they stack up pretty quickly.


The only way I found to get around this is to have a variable outside the closure and then to wrap the GetObject function with an If statement to check if a handler has already been attached and then set the lb.callbackFn = null when I'm done to avoid a loop.

var attached = false;     // outside of the closure

if(!attached){

     attached = true;

          var obj = doc.GetObject("LB02");

          obj.callbackFn = function() {

               var arr = ["TextValue"];

               this.Data.SelectTexts(arr);

               this.callbackFn = null;

     }

}

If anyone has a better way of doing this, please share.

Hope this helps someone else at some stage.

View solution in original post

1 Reply
organgrindingmo
Partner - Contributor III
Partner - Contributor III
Author

I have found the solution which is rather simple. You can only do a selection on dimensions within the Extension using SelectTextsInColumn(Column, toggle, recordsToSelect), the Column parameter refers to which dimension you want to select in.

All I had to do was add an extra Composite Key Dimension and then select on that Column.

ie: SelectTextsInColumn(2, true, "compKeyValue"); where the 2 refers to the 3rd item in my dimension array.

0 = product, 1 = province and 2 = compKey

The rest of the post is not part of the solution that I used but was part of the question so I thought I'd post it anyway.

I've also found out why I couldn't use the GetSelected() function on the ListBox. The document.GetObject("ObjectId", callbackFn) uses a callback to return the object. I was calling the GetSelected function on the object reference before it was returned.


Within the callback the this.Data.SelectTexts() function works but it brings other problems, the GetObject() function appends another callback to your object every time a selection is made and it gets an additional one because the Extension has rerendered which also attaches yet another callback. So they stack up pretty quickly.


The only way I found to get around this is to have a variable outside the closure and then to wrap the GetObject function with an If statement to check if a handler has already been attached and then set the lb.callbackFn = null when I'm done to avoid a loop.

var attached = false;     // outside of the closure

if(!attached){

     attached = true;

          var obj = doc.GetObject("LB02");

          obj.callbackFn = function() {

               var arr = ["TextValue"];

               this.Data.SelectTexts(arr);

               this.callbackFn = null;

     }

}

If anyone has a better way of doing this, please share.

Hope this helps someone else at some stage.