6 Replies Latest reply: May 27, 2014 8:36 AM by Mattia Musso RSS

    Tweaking UI with JS and CSS

    Oleg Troyansky

      Hi everybody,

       

      I have a question for those who understand JavaScript and CSS and it's relationship with QlikView...

       

      A client of mine is an OEM partner that has an analytic template that is implemented and customized at multiple end clients. We are exploring a possiblity of automating the customizations to the highest possible degree. Do you have any thoughts and "lessons learned" about hte possibility to tweak the default QlikView output in real time, using JavaScript and/or CSS. For example:

       

      - Remove or hide certain objects on the screen

      - Move remaining objects around to close the gaps when certain objects are removed/hidden

      - (I know this is getting tricky) Adding objects that may be coming from another QV document or sheet?

       

      Any "real-life" feedback would be very helpful - what's possible? what's not? what's working or not? Is there a noticeable performance hit?

       

      thanks a lot!

       

      Oleg Troyansky

        • Re: Tweaking UI with JS and CSS
          Brian Munz

          Hi Oleg,

          So using document extensions to do what you're saying is definitely possible, especially the first two items you listed.  In general, by the time you see a QliKView sheet in the AJAX client it's just a website.  Because of that, most of the things you do using javascript and CSS in a regular site are possible here.

          You've actually spurred me on to finally put my front end doc extension demo out on community:

          http://community.qlik.com/docs/DOC-4243

          I've been showing it for a while in my presentations as a sort of fun way to show how much you can mess with the UI from a doc extension.  It's not well documented (which is why I never made it available), but the code could offer some insight to how to best approach your situation.

          Some highlights/lessons learned:

          • A document extension runs when the page is first loaded, it does not wait until all of the element on the page are rendered.  So if you put code in that is trying to target or change an HTML element, it may not even be able to find that element yet.  Due to this, you should use this code, which fires off a function after the page has loaded: this.Document.SetOnUpdateComplete(someFunction);
          • Adding the CSS sheet is easy (see the extension I pointed to) but navigating your way through all of the HTML code to target/style the proper elements can be difficult.  It takes some patience and some trickery but you can usually get to the objects pretty well.  What you MUST get is the FireBug extension found here: http://community.qlik.com/thread/66688  By far the most useful tool there is in extension development.  It lets you see the actual HTML code and even modify the CSS on the fly while seeing the page update.
          • QlikView 11 has jQuery built into it.  Use it.  It makes this kind of thing so much easier.

           

          To address your 3 scenarios directly...

          • Removing and hiding elements on a screen is easy.  Targeting them, like I said earlier, may not be.  In fact a lot of things weren't possible before because there was no sensible way to target, in javascript, one listbox over another for example.  The good news is that in v11 SR2 some code was added which adds a class to each object with its QlikView ID in it.  GET THE FIREBUG EXTENSION.  So, for example, if you have a chart with the ID of CH08, the class of the div would be "Document_CH08."  Now that this object has a class that identifies it, we could easily hide it using jQuery by simply doing: $(".Document_CH08").hide()
          • This could also be done, but I'm not saying it's going to be easy.  You'd have to target the element you're looking to put the new element near and find out its position on the page.  Then you could calculate where to place the new element nearby.  I'm not sure how QlikView would react though as you switch between sheets and that kind of thing.
          • Yikes.  So as I think about it...yes, this is probably possible, but it'd be getting a little crazy and have a lot more potential for some major hurdles.  You'd pretty much have to go rogue through a series of AJAX calls to the server...or something.  I'm not sure.  It might be possible it might not.  It would be if you were willing to modify the actual base code of the product itself which would make your product no longer supportable.

          Okay, so that's probably way more than you needed, but I thought it might be helpful to get all those tips out there.

          Let me know if you have any more questions.

            • Re: Tweaking UI with JS and CSS
              Oleg Troyansky

              Brian, thanks a lot for a very quick and very thourough answer. This is exactly what I was looking for!

              • Re: Tweaking UI with JS and CSS
                Patrik Seger

                Hi

                 

                Thanks for this, great post!

                 

                I have always had huge problems with extension objects when changing tabs and from my reverse engineering it looks like the complete body is changed between tabs so all my extension objects just disappears (or appears) as of a sudden when the user changes tabs. The script though resides in the head so I can keep track on the JavaScript part.

                 

                Have you any ideas/knowledge to spread on what really happens when the user changes tabs?

                 

                I would need to get more feedback what happens, eg if a user removes an extension object changes tab or closes the document. I guess you can use the JavaScript document callbacks to some extent but it would be nice to get more info from QlikView what really happens...

                 

                Br Patrik

                  • Re: Tweaking UI with JS and CSS

                    Hi,

                    I have a same problem with extension object.

                    I used Jquery-UI accordion , its ok for the first tab, but when i show the rest of tabs,

                    There are only white containers without any info.

                    Fortunately, when i right click and chose any actions (like : select ), info appears.

                    So,in my opinion,It means that when Css or Javascript hide the container of QlikviewObject,

                    the Server of Qlikview want not to charge info, until u get any action.

                    Maybe, there is any configuration in Qlikview Server to make sure it buffer out all info when we

                    load our page?

                     

                    Best regard.

                      • Re: Tweaking UI with JS and CSS
                        Patrik Seger

                        Hi

                         

                        To handle this problem, I use two different mechanisms. One that detects if the EO has been initiated before (by checking if there are elements):

                             function qvPaint(qvSource) {

                             ...

                             if (qvSource.Element.children.length === 0) {

                                  // First time in document or in tab...

                                  // When tab changes you enter here, but all JS globals are initiated

                             }

                         

                        The second I use is to detect if this is the first time the EO is running since document opened. This code is put outside of the qvPaint function (can be coded shorter ):

                             if (typeof qvFirstTime === 'undefined') {

                                  // First time EO is running
                                  var qvFirstTime = true;

                             }

                             else {

                                  // EO has initited before

                                  qvFirstTime = false;

                             }

                        Then you can use this variable to do stuff you need to handle the first time the EO is running.

                         

                        Br Patrik

                        • Re: Re: Tweaking UI with JS and CSS

                          Hi xinsheng,


                          Can you shared your project with JqueryUi - Accordion? I was trying to add the JqueryUi plugin in my project but it doesn't work. Can you help me?

                           

                          Thank's

                          Mattia