QvUtils.js
QvUtils.js is a lightweight library which extends the native QlikView JS API and in addition provides some extra useful functions to make the life of a QlikView Extension developer a little bit easier.
QvUtils.js consists of three parts:
Zipped Package |
createDivthis.createDiv([id = Document_CHX])
Appends a new DIV-element to the Extension container. The element id will the Object Extension id with backslashes replaced by underscores, i.e Document_CH01
1. [id=Document_CHX]
(string) - The element ID.
(object): Returns a jQuery Object
//Create a standard DIV Qva.AddExtension('MySampleExtensions', function() { var $mydiv = this.createDiv(); $mydiv.css('backgroundcolor', 'green'); }
//User-defined id Qva.AddExtension('MySampleExtensions', function() { this.createDiv('MyID'); //select the element through jQuery $('#MyID').css('backgroundcolor', 'green'); }
getDatathis.getData()
Returns a object containing the data exposed to the extension.
Contains both a row matrix and a column matrix of data and its associated metadata.
(object): Returns the data object
Qva.AddExtension('MySampleExtensions', function() { var data = this.getData(); //Get first column data.Column[0] //Get first column label data.Column[0].label //Get the value of first row and second column data.Row[0][1].text //Get the value of first column and the first value data.Column[0][0].text }
showDatathis.showData()
Prints out available QlikView data that's exposed to the extension. Useful for debugging your data structure and identifying nulls and missing values..
//Print out available data Qva.AddExtension('MySampleExtensions', function() { this.showData(); // -> Prints out a data table in your extension }
createTabrowthis.createTabrow([opt])
Extends Document.SetTabrowPaint(callbackFn)
Creates a rudimentary tabrow and appends it to the page for easy styling via css.
HTML - structure:
- div - Container
-- ul - Unordered list
--- li - Tab
---- a - Tabname
1. (object): Configuration Object - Default values below
div: { id: 'tabrow', classes: 'tabrow' }, ul: { id: 'root', classes: 'tabrow' }
//Create a generic tabrow Qva.AddDocumentExtension('MySampleExtensions', function() { //Load CSS to style our tabrow Qva.LoadCSS('path to style.css') this.Document.SetTabrowPaint(function() { //Create generic tabrow this.createTabrow(); }); }
//Create a custom tabrow Qva.AddDocumentExtension('MySampleExtensions', function() { //Load CSS to style our tabrow Qva.LoadCSS('path to style.css') this.Document.SetTabrowPaint(function() { //Create tabrow with custom id's and classes this.createTabrow({ div : { id: 'myCustomId', classes: 'my multiple class names' } }); }); }
qvutils.getRandomqvutils.getRandom(min,max)
Returns a random integer between min and max, inclusive. If you only pass one argument, it will return a number between 0 and that number.
1. min
(number): Min number or Max number when passed as single argument
2. [max]
(number): Max number
//Random number between 0 and 100 qvutils.getRandom(100) //Random number between 50 and 60 qvutils.getRandom(50,60)
qvutils.isBooleanqvutils.isBoolean(value)
Checks if value is a boolean value.
1. value (*): The value to check.
(boolean): Returns true if the value is a boolean value, else false.
qvutils.isBoolean(null); //Returns false
qvutils.isNullOrEmptyqvutils.isNullOrEmpty(value)
Checks if value is null, empty or undefined.
1. value (*): The value to check.
(boolean): Returns true if the value is empty, null or undefined.
Qva.AddExtension('MyExtension', function() { qvutils.isNullOrEmpty(this.Layout.Text0.text); //Checks if extension property has been filled in })
qvutils.isNumberqvutils.isNumber(value)
Checks if value is a number
1. value (number): The value to check.
(boolean): Returns true if the value is a number, false otherwise
qvutils.isNumber(5 * 100) //true qvutils.isNumber('10') //true qvutils.isNumber('HelloWorld') //false
qvutils.transposeqvutils.transpose(array)
Transposes a multi dimensional array. Useful to transpose a multi-dimensional row array into columns etc.
1. array (array): The array to transpose
(array): Returns a new array that has been transposed.
Qva.AddExtensions('MyExtensions,' function() { qvutils.transpose(this.Data.Rows); //Returns a columnar representation of the row data. })
qvutils.getMinqvutils.getMin(array, [prop=data])
Returns minimum value from an array of objects.
Useful to determain the lowest value of a expression column.
1. array (array): The array of objects 2. [prop='data'] (string) The Object property holding the values. Defaults to "Data" which is QV native.
(number): Returns the minimum value.
Qva.AddExtension('MyExtensions,' function() { var data = this.getData(); qvutils.getMin(data.Column[1]) //Returns the minimum value of the expression column. })
qvutils.getMaxqvutils.getMax(array, [prop=data])
Returns mxaimum value from an array of objects.
Useful to determain the maximum value of a expression column.
1. array (array): The array of objects 2. [prop='data'] (string) The Object property holding the values. Defaults to "Data" which is QV native.
(number): Returns the maximum value.
Qva.AddExtension('MyExtensions,' function() { var data = this.getData(); qvutils.getMax(data.Column[1]) //Returns the maximum value of the expression column. })