Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
vegard_bakke
Partner - Creator III
Partner - Creator III

Extension with qListObjectDef and extra expressions

I'm trying to make an extension that uses qListObjectDef, instead of qHyperCubeDef.  Reason being that I want to receive all rows for the dimension, even though one of the values have been selected. (Such as for a Filter. And not as a Table.)

 

In addition to that, I need a couple of extra expressions per value.   

 

I know you can do this as a mashup, using 'qExpressions' and app.createList(). 
But how do I get the properties definition right in an extension to do the same?


Hoping for any hints,
Vegard 🙂

1 Solution

Accepted Solutions
Øystein_Kolsrud
Employee
Employee

If you want to evaluate expressions for the values, then list objects is probably not the way to go as those structures only allow you to have one dimension. But I have two ideas that might do the trick for you:

  1. Create an alternate state and use that for the object containing your hypercube. This object will then not be affected by the selection in the default state.
  2. Keep the hypercube in the default state, but add a column with an expression that refers to the global state. For instance like this: "Count({1} 1)" That will force the hypercube to compute values across all values.

I'd consider 2) to be sort of a hack though, but the advantage is that you don't need to create any new alternate state in your app.

View solution in original post

3 Replies
Øystein_Kolsrud
Employee
Employee

If you want to evaluate expressions for the values, then list objects is probably not the way to go as those structures only allow you to have one dimension. But I have two ideas that might do the trick for you:

  1. Create an alternate state and use that for the object containing your hypercube. This object will then not be affected by the selection in the default state.
  2. Keep the hypercube in the default state, but add a column with an expression that refers to the global state. For instance like this: "Count({1} 1)" That will force the hypercube to compute values across all values.

I'd consider 2) to be sort of a hack though, but the advantage is that you don't need to create any new alternate state in your app.

vegard_bakke
Partner - Creator III
Partner - Creator III
Author

Thank you, yko. This extension is for one dimension, only, although I need a few extra measures per dimension value. Therefore qListObjectDef would have been perfect, as it does not collapse to selected rows only. 

I find it strange that it works for app.createList() in a mashup, but not in an extension, though.

Nevertheless, thanks for you suggestion. I'll think I'll stick to the hack (no. 2) for this one.  🙂

vegard_bakke
Partner - Creator III
Partner - Creator III
Author

I found: https://github.com/alner/qsSimpleList, which had an example with expressions on a qListObjectDef!

 

Unfortunately, the expression was only calculated for the selected value. 

So I tried the 'Test 2' below, storing the variable in a temporary property ('extra'), building up an 'Only( {1} )' expression using his change() trick. 

 

Seems to be working in my current tests at least. 🙂

 

My definition is currently:

define( [], function () {
    'use strict';
    return {
        initialProperties: {
            qListObjectDef : {
                qShowAlternatives : true,
                qFrequencyMode : "V",
                qSortCriterias : {
                    qSortByState : 1
                },
                qInitialDataFetch : [{
                    qWidth : 3,
                    qHeight : 50
                }],
                
            }
        },
        
        definition: {
            type: "items",
            component: "accordion",
            items: {
                dimension: {
                    type: "items",
                    translation: "Common.Dimension",
                    ref: "qListObjectDef",
                    min: 1,
                    max: 1,     
                    items: {
                        cId: {
                            ref: "qListObjectDef.qDef.cId",
                            type: "dimension",
                            show: !1
                        },
                        libraryId: {
                            type: "string",
                            component: "library-item",
                            libraryItemType: "dimension",
                            ref: "qListObjectDef.qLibraryId",
                            label: "Dimension",
                            translation: "Common.Dimension",
                            show: function(e) {
                                return e.qListObjectDef && e.qListObjectDef.qLibraryId
                            }
                        },
                        label: {
                            type: "string",
                            ref: "qListObjectDef.qDef.qFieldLabels.0",
                            label: "Label",
                            translation: "Common.Label",
                            show: !0
                        },
                        field: {
                            type: "string",
                            component: "expression",
                            expression: "always",
                            expressionType: "dimension",
                            ref: "qListObjectDef.qDef.qFieldDefs.0",
                            translation: "Common.Field",
                            show: function(e) {
                                return !e.qListObjectDef.qLibraryId
                            },
                            change: function(def) {
                                var t = def.qListObjectDef.qDef;
                                t.qFieldLabels || (t.qFieldLabels = []),
                                t.qFieldLabels[0] = t.qFieldDefs[0]
                            }
                        },
                        expression: {
                            translation: "Common.Measure",
                            type: "string",
                            component: "expression",
                            expressionType: "measure",
                            ref: "qListObjectDef.qExpressions.0.qExpr",
                        },
                        test2: {  // My test
                            translation: "Test 2",
                            type: "string",
                            component: "expression",
                            expressionType: "measure",
                            //ref: "qListObjectDef.qExpressions.1.qExpr",
                            ref: "extra.1",
                            change: function(def) {
                                let i = 1;
                                if (def.extra[i]) {
                                    let field = def.extra[i];
                                    let expr = '=Only( {1} ' +field')';
                                    def.qListObjectDef.qExpressions[i] = {qExpr: exprqLibraryId: ""};
                                }
                            }