4 Replies Latest reply: Feb 6, 2017 10:49 AM by Emil Rånge RSS

    How to render Export to Image after getData has finished

    Emil Rånge

      I have made an extension that get data from backend

      (Like this: backendApi.getData( requestPages ))

       

      When I export to Image I do not see any data. Most likely because paint returns before backend have respond with data.

       

       

      I think the solution to this is to use "finished rendering" some how.

      (last part in this link)

      https://help.qlik.com/en-US/sense-developer/3.1/Subsystems/Extensions/Content/Howtos/extensions-enable-export.htm

       

       

      I do not understand how to use it:

      paint : function() { return qlik.Promise.resolve(); }

      (qlik is not defined)

       

      How do I find variable qlik? If I find it, will it work? I guess the getData callback must tell that the extension has finished rendering...

        • Re: How to render Export to Image after getData has finished
          Emil Rånge

          I found varibale 'qlik', I just had to write

          define( ["js/qlik"],function(qlik){

          at the top.

           

          Still the problem is that I get a blank page when export to image and quite still sure I has to do with that the paint method returns before the backend calls are done. I have tried to add :

          return qlik.Promise.resolve();

          in paint method and it still does not work.

           

          The thing is that I have many backend calls that call other backend calls (that draw extension) and it would be great if I could just call some kind of callback when the draw of the extension is complete.

           

          ...

          I will return with an example code of the problem since I think it is hard to understand the issue.

            • Re: How to render Export to Image after getData has finished
              Emil Rånge

              Here is the code:

                var requestPages = [{

                  qTop: 0,

                  qLeft: 0,

                  qWidth: 1,

                  qHeight: 10

                }];

               

               

                this.backendApi.getData( requestPages ).then( function ( dataPages ) {

                  $element.empty();

                  var matrix = dataPages[0].qMatrix;

                  var ul = document.createElement("UL");

                  $element.append(ul);

                  for(var i=0; i<matrix.length; i++) {

                    var li = document.createElement("LI");

                    li.append(document.createTextNode(matrix[i][0].qText));

                    ul.append(li);

                  }

                })

               

               

                return qlik.Promise.resolve();

               

              I can see the data.

               

              But when I export to image I just see a blank page. How can I make sure the image is being exported after html been created.

            • Re: How to render Export to Image after getData has finished
              Emil Rånge

              I found a solution for this some weeks ago. I post answer here in case someone else is in need of solution.

               

              call resolve when extension is a state ready for export like this.

                  paint: function ( $element, layout ) {

                        return new Promise(function(resolve,reject) {

               

               

              Also a short timeout just before resolve is good since I had some issues see the data that were draw on extension just before resolve().

              setTimeout(function(){ resolve(); }, 100);