5 Replies Latest reply: Mar 3, 2017 6:49 AM by Richard Bartley RSS

    Creating a dynamic exportData button / re-using same button for exporting data

    Richard Bartley

      Hello everyone,

       

      I have a mashup and am trying to implement a toolbar panel (see below) that allows users to download data for different charts according to which one is displayed at the time.

       

       

       

       

       

       

      While I have no problem with exporting data using a different button for each chart, e.g.

       

       

      app.getObject('QV52','uHQnzX').then( function( vizModel ) { 

          

           $('#cmdExport1').show(); 

            $('#cmdExport1').prop('onclick',null).off('click');

          

            $('#cmdExport1').on('click', function() { 

          

            vizModel.exportData().then(function( reply ) { 

            var url = 'http://' + config.host +'/auth'+reply.result.qUrl;

            window.open(url);

           

            }); 

            });

          

          

          

           });

       

      app.getObject('QV53','uHQnzY').then( function( vizModel ) { 

          

            $('#cmdExport2').show(); 

           $('#cmdExport2').prop('onclick',null).off('click');

          

           $('#cmdExport2').on('click', function() { 

          

            vizModel.exportData().then(function( reply ) { 

            var url = 'http://' + config.host +'/auth'+reply.result.qUrl;

            window.open(url);

           

            }); 

            });

          

          

          

           });

       

      Since I am allowing the users to change the displayed chart, I would like to use a single button in the panel to  download the data of the selected chart.  I tried using the function below, but it does not seem to allocate the onclick function correctly.  I assume this is due to the fact that the function is called before the charts are fully loaded in memory.

       

      function updateDownloadButton(qlik,app,strObjectID)

      {

       

      console.log('updateDownloadButton=  ',strObjectID);

      var object = app.getObject('x','vsbGw'); 

      object.then(function(model) { 

           console.log('in object.then');

              var table = new qlik.table(model); 

        $('#cmdExport1').on('click', function() { 

                  table.exportData({download: true}); 

              }); 

          

        });

       

       

      Does anyone have any ideas?

       

      Thanks in advance,

       

      Richard