Qlik Community

Qlik Sense Integration, Extensions, & APIs

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

nicolas_martin
Contributor II

How to display an evaluated expression?

Hello,

In an extension, the rendering is done in the "paint" function.

For instance:

paint : function($element, layout) {

  $element.html("Hello World!") ;

}

will display "Hello World!".

I would like to know how I can evaluate the string as a QlikView expression, something like that:

paint : function($element, layout) {

  $element.html("=today()") ;

}

or

paint : function($element, layout) {

  $element.html("='you have ' & count(DISINTCT Element) & ' elements'") ;

}

Thank you.

4 Replies
erik_wetterberg
Honored Contributor

Re: How to display an evaluated expression?

Hi,

You could set up an expression in your initial properties. Somthing like:

initialProperties : {

      version : {

                    qStringExpression : "=QlikViewVersion ()"

      },

      fields : {

                    qValueExpression : "=Count (DISTINCT $Field)"

                }

,......

               

this will give you version in the field layout.version and number of fields in layout.fields. If the values change, your paint method will be called again with the new values.

Erik

Erik Wetterberg
https://extendingqlik.upper88.com/
nicolas_martin
Contributor II

Re: How to display an evaluated expression?

I tried to add this lines in my "initialProperties", but I cannot access to the new "layout.fields" and "layout.version".

(I'm using Firebug to explore the object "layout")

I'm trying to modify the "HTML Box" object, so it could compute the string:

define(["jquery","./com-itelligence-htmlBox-properties"], function($,properties) {

  return {

  type : "it.HTML Box",

  //Refer to the properties file

  definition : properties,

  initialProperties : {

  version: 1.0,

  qHyperCubeDef : {

  qDimensions : [],

  qMeasures : [],

  qInitialDataFetch : [{

  qWidth : 0,

  qHeight : 0

  }]

  },

  fontSize : {

  min : 8,

  max : 24

  },

  test : {

  qStringExpression : "=QlikViewVersion ()"

  }

  },

  snapshot : {

  canTakeSnapshot : false

  },

  paint : function($element, layout) {

  //$element.html("$(" + layout.qDef['HTML'] + ")") ;

  $element.html(layout.test) ;

  //$element.html(layout.qDef['HTML']) ;

  }

  };

});

I've added a "test" property --> I can't access it with "layout.test".

My aim is to be able to set

='you have <b>' & count(DISTINCT $Field) & '</b> fields in your application'

in my HTML parameter, instead of a simple static string.

erik_wetterberg
Honored Contributor

Re: How to display an evaluated expression?

Since the initialProperties is used when you create the object, you need to recreate it.

Erik Wetterberg
https://extendingqlik.upper88.com/
nicolas_martin
Contributor II

Re: How to display an evaluated expression?

It works better for a static value.

However, if the value is hard-coded, the user can't change it.

Community Browser