Sunday, 9 January 2011

Beginners Guide to QlikView Extension Objects : Part 3

So, we have created custom extensions that display data from QlikView.  However, we need to make that object respond to clicks and make selections back in the QlikView document.

This is achieved using the SelectRow function of the Data object.  When we write out our data, we need to make sure that we keep track of what row that data came from so that we can execute an “onclick” function to call SelectRow with that row number.  QlikView will then make that selection and refresh the data.

Here is the adjusted code to handle this:

Qva.AddExtension('CVL/BasicTable', function() {

        // Create a variable to hold generated html
        var html = "<table>";
        // Local variable to hold the reference to QlikView
        var _this = this;

        // function to handle users clicking on a row
    window.oncvlrowclick = function(rowIx)
    {
        _this.Data.SelectRow(rowIx);
    }

        // Cycle Through the data
          for (var i = 0; i < this.Data.Rows.length; i++) {
                // get the row
        var row = this.Data.Rows [i];

                // Generate html
                html += "<tr><td onclick='oncvlrowclick("+i+")'>" + row[0].text + "</td><td onclick='oncvlrowclick("+i+")'>" + row[1].text + "</td></tr>";
    }

        // Finalise the html
        html += "</table>";

        // Set the HTML
    this.Element.innerHTML = html;

},true);

OK, that is it.  Time for you to take over and start creating your own objects.  You now have the tools to create an object, populate it with QlikView data, and make it respond to clicks.

Enjoy.

Beginners Guide to QlikView Extension Objects : Part 2

In the last part, I showed how to create a really basic extension object.  Now, I will build on that to use data from my QlikView application.

I am going to add a sub-folder to my CVL folder called “BasicTable” (so, CVL\BasicTable will be the sub-folder).

I need a definition.xml, icon.png and script.js.  The quickest way to build these is to copy them from the previous project and then modify.

The initial contents of my definition will be:

<?xml version="1.0" encoding="utf-8"?>
<ExtensionObject  Label="CVL Basic Table" />

Now, we can concentrate on the JavaScript to generate the output.

The QlikView object holder (which we can access via “this” in our JavaScript) defines an object called “Data” which will define the data passed by the object from the QlikView document.  The data passed will depend on the Dimensions and Expressions defined in the properties of the object.

The Data object has a Rows property.  Each Row in Rows is an array of values.  The index corresponds to the number of Dimensions and Expressions.  In a simple example, with one Dimension and one Expression, there will be 2 values in the array – 0 and 1.  In multi-dimensional or multi-expression objects, the Dimensions will be the first values in the array, followed by the Expressions.

Lets define some code to cycle through the data and present it in a simple html table.

Qva.AddExtension('CVL/BasicTable', function() {

        // Create a variable to hold generated html
        var html = "<table>";

        // Cycle Through the data
          for (var i = 0; i < this.Data.Rows.length; i++) {
                // get the row
        var row = this.Data.Rows [i];

                // Generate html
                html += "<tr><td>" + row[0].text + "</td><td>" + row[1].text + "</td></tr>";
    }

        // Finalise the html
        html += "</table>";

        // Set the HTML
    this.Element.innerHTML = html;

},true);

Now, if you add this object to a document, you won’t see anything.  This is because we need to specify the Dimension and Expression first before any data will become available.

It is possible to define a default, of sorts, for Dimension and Expression.  You could define an actual name or expression but, not every document might have that name and this could cause problems.  If we set a blank default for Dimension and Expression, then QlikView will pick the first dimension and the sum of the first number value in the document as defaults.  This gives something to show when the object adds (which might cause other problems!).  To do this, we modify the definition.xml file.  I am also going to define a default caption here:

<?xml version="1.0" encoding="utf-8"?>
<ExtensionObject Label="CVL Basic Table">
    <Dimension Initial="" />
    <Measurement Initial="" />
    <Initiate Name="Caption.Text" value="CVL Basic Table" />
</ExtensionObject>

By the way, if you do make changes to the definition.xml or script.js files, it is not necessary to close and reopen QlikView to see those changes.  Simply press F5 and QlikView will refresh.  This is very useful in debugging.

Speaking of debugging, I’m afraid that the best way I have found to debug these JavaScript files is to add alert statements.

In the next part, I will show how to add code to handle when a user clicks in your custom object that will make a selection in your QlikView document.

Beginners Guide to QlikView Extension Objects : Part 1

I thought that I might write a quick guide to creating an extension objects for QlikView 10.

What is an extension object?  Well, it allows us to create a chart using html and javascript or consume a 3rd party flash/silverlight object.  Our chart can use data from QlikView and it can pass click events back to QlikView.  Basically, we can create any chart that we want that doesn’t exist already.

You might think that there would be a whole lot of work to do to create this, but it is actually really simple to get a chart up and running and consuming QlikView data.

Extension objects live in the C:\Users\your.username\AppData\Local\QlikTech\QlikView\Extensions\Objects folder for desktop users.  Each extension must have a folder for itself.  However, you can have multiple sub-folder levels if you want.

The first thing that I will do in the Objects folder is create a sub-folder for my company’s extensions.  My company is Capricorn Ventis Ltd. so I will create a folder called CVL.  In this folder, I will create a sub-folder for each extension.  First one that I am going to create is HelloWorld (doesn’t every example have to start with a Hello World!).  Now, under the Objects folder, I have CVL\HelloWorld.

Every extension has a minimum of 1 file associated with it - Definition.xml.  This file will define the element, ExtensionObject (which can have other sub elements to, for example, set some default values):

<?xml version="1.0" encoding="utf-8"?>
<ExtensionObject />

That’s it – simple.  We will have a look at some additional options for this file in the next part.

With this one file in the HelloWorld folder, I can now see in QlikView (in Web View mode) when I right-click and select New Sheet Object, Extension Objects, I will see my new CVL/HelloWorld object (with no icon) which I can drag onto the sheet and it will create an object.  It won’t be a very awe inspiring object (a blank box) but you can set properties (such as caption) just as you would for other charts.

We need to add a couple of things to make this just a little more advanced.  First, if we want to have an icon (and you really should), we need to add a 24x24 PNG file called icon.PNG to the folder – any design that you want.  Next, I am going to make a small modification to the Definition.xml file:

<?xml version="1.0" encoding="utf-8"?>
<ExtensionObject  Label="CVL Hello World" />

This label will be what is displayed in the New Sheet Object dialog – next to the icon defined by the PNG file.

Now that those aesthetics are sorted out, we can make the object actually do something.  We need to add a JavaScript file that will define the code that will be run by this object.  The file is always called script.js.  This js file must define a call to Qva.AddExtension which defines a name and function that will be called when the extension loads:

Qva.AddExtension('CVL/HelloWorld', function() {
   // Set the HTML
   this.Element.innerHTML = "<h1>Hello World</h1>";
},true);

Note that the name defined in AddExtension is the same as the path to the folder as it would be from the Objects folder.  This is required.

This code is very simple – it just outputs some simple html – but it reveals how we can do some much more advanced stuff.  If we can generate html, we can output it to our application and do so much!  All we need now is some data.

In the next part, I will show you how to consume QlikView data.

Friday, 7 January 2011

Things I like about QlikView 10 - Part 3: Extension Objects

This is possibly the coolest thing in QlikView.

We were working with a client a while ago who had a very specific requirement for a visualisation. We worked several options with different show/hide options around bar charts and pivot tables but, while they were close to what was required (close enough anyway), they didn't quite hit the mark.

Now I know that i can build exactly what they want with an extension object. I know that I can do this because I know HTML and JavaScript - I know what I can do with it. I don't even need to go to flash/silverlight, I can work wonders in notepad.

Have you had a go yet?

Things I like about QlikView 10 - Part 2: UI

I am quite liking the new container object. My only problem is that I keep forgetting about it and creating loads of separate charts with minimized icons - then it's "Doh!" It is cool though.

Linked objects are starting to save a whole load of time - especially those date list boxes that I will have on most every sheet in a document. Being able to link and then change once is a great boon.

Many of our customers now use Ajax as their primary client. Therefore the WebView option in QlikView desktop is really cool. Being able to wysiwyg in Ajax is great.

Things I like about QlikView 10 - Part 1: Script

One of my favourite things about v10 is the changes that they have made to the load algorythm to multi-thread the symbol table creation. While you won't notice it so much up to a couple of hundred thousand rows of data, when you get into the millions it makes such a difference.

I am also a big fan of the new QVConnect process that allows you to use a 32bit driver on a 64bit server. It isn't something that we have run into everywhere but we have had a few customers with Accounting systems that only provided 32bit ODBC drivers. Now, it isn't even a consideration. Yay!

Within the script editor itself, the script syntax checking is taking some getting used to but is starting to save me a whole load of time. I am really enjoying the auto-complete here too.