Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
rbartley
Specialist II
Specialist II

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

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

1 Solution

Accepted Solutions
Alexander_Thor
Employee
Employee

Hey Richard,

You could always do something like: Export data - JSFiddle

Now the sample actually wont work since it's a anonymous user that aren't allowed to export but if you check the traffic you'll see that the ExportData method is indeed firing for the correct chart/handle.

View solution in original post

5 Replies
Alexander_Thor
Employee
Employee

Hey Richard,

You could always do something like: Export data - JSFiddle

Now the sample actually wont work since it's a anonymous user that aren't allowed to export but if you check the traffic you'll see that the ExportData method is indeed firing for the correct chart/handle.

rbartley
Specialist II
Specialist II
Author

Hi Alexander,

Thanks for responding.  I get a syntax error when using the JSFiddle you provided:

This seems to refer to the the following line:

currentChart.then(model => {

Any ideas?

rbartley
Specialist II
Specialist II
Author

Alexander,

I adapted the JSFiddle script to use the following:

currentChart = app.getObject('chart', 'vsbGw');

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

    currentChart.then(function(model){

    var table = new qlik.table(model);

    return table.exportData({download: true})

     })

     .then(function(url) {

    console.log(url)

     })

  });

This overcame the syntax error problem and also works for pie charts, but generates an error when attempting to export map data:

I assume that this is related to the format of the geographical data.  Any ideas how to get around this or exclude certain fields?

Thanks in advance

Alexander_Thor
Employee
Employee

Oh sorry about that, I used the new ES6 which I don't think IE supports hence the syntax errors.
I don't know about the map, let me check on that.

rbartley
Specialist II
Specialist II
Author

Hi Alex,

Any news on whether it's possible to export map data or not?

Richard