Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
mdbender
Contributor II
Contributor II

Get data from table or chart

Hi all!

I'm new with qlik sense and it's API.

I've made extension which paints button. We have table with manages and another table with their results. After selecting manager content of the second tables filled with his results. How can I reach this data in my extension after clicking button?

define(["jquery", "qlik", "text!./lib/css/CommandButton2.css"], function($, qlik, cssContent) {

  $("<style>").html(cssContent).appendTo("head");

    return {

     paint: function ($element, layout) {

       // Display Extension Visualization
       var html = html = '<button id="modal-open2" class="btn btn-primary">Work</button>';

      $element.html(html);

    

       // Open modal
       $("#modal-open2").on('click', function(){

         alert('ok');

         console.log('Data returned: ', layout.qMadeSelections);

         // Do some job
         return false;

       })

    }

  }

});

1 Solution

Accepted Solutions
Alexander_Thor
Employee
Employee

Properties of an object does not contain data, only the expanded layout does. And in the case of native visualizations very few actually contain the data upfront but rather it is paged in on a need basis.

However is some code to fetch pages of data from a object.

And here is the interactive version of said code: Get Object Data - JSFiddle

    const app = qlik.openApp('d7b1f94e-749b-479a-9bad-fcb8fccda5dc', config);

    

    app.getObject("rJFbvG").then(model => {

      // Contains the full size of the hypercube, qcx which is the width

      // or number of columns and qcy the height or number or rows

      console.log(model.layout.qHyperCube.qSize);

   

      // Fetch a page of data. A single page can maximum contain 10000

      // cells. Calculate the page size and number of pages based of qSize

      // and fetch accordingly.

      model.getHyperCubeData('/qHyperCubeDef', [{

        qTop: 0,

        qLeft: 0,

        qWidth: 10,

        qHeight: 1000

      }]).then(data => console.log(data))

    })

View solution in original post

9 Replies
mdbender
Contributor II
Contributor II
Author

May be answer can be in Engine API?

Alexander_Thor
Employee
Employee

I'm not sure what you are looking to do but the Capabilities API has a method called getObject which lets you fetch other objects beside your extension.

mdbender
Contributor II
Contributor II
Author

Thank You! I find this page - https://help.qlik.com/en-US/sense-developer/3.1/Subsystems/EngineAPI/Content/Classes/AppClass/App-cl...

I added this code

// object table
console.log('Data returned: ', qlik.currApp().getObject("pKYZVU"));

// properties of object
qlik.currApp().getObjectProperties("pKYZVU").then(function(model) {
  console.log('Data returned: ',model.properties);
});

But I still can't find data from table in this object. What to do for fetching them?

Alexander_Thor
Employee
Employee

Properties of an object does not contain data, only the expanded layout does. And in the case of native visualizations very few actually contain the data upfront but rather it is paged in on a need basis.

However is some code to fetch pages of data from a object.

And here is the interactive version of said code: Get Object Data - JSFiddle

    const app = qlik.openApp('d7b1f94e-749b-479a-9bad-fcb8fccda5dc', config);

    

    app.getObject("rJFbvG").then(model => {

      // Contains the full size of the hypercube, qcx which is the width

      // or number of columns and qcy the height or number or rows

      console.log(model.layout.qHyperCube.qSize);

   

      // Fetch a page of data. A single page can maximum contain 10000

      // cells. Calculate the page size and number of pages based of qSize

      // and fetch accordingly.

      model.getHyperCubeData('/qHyperCubeDef', [{

        qTop: 0,

        qLeft: 0,

        qWidth: 10,

        qHeight: 1000

      }]).then(data => console.log(data))

    })

mdbender
Contributor II
Contributor II
Author

It works greats! Thank you!

Why do you use "then(data => console.log(data))" but not "then(function(data) { // do job})"

Alexander_Thor
Employee
Employee

It's ES6 syntax for arrow functions (not supported in all browsers) so you can safely use function() {} as well as it does the same thing.

sebastian_serva
Partner - Contributor III
Partner - Contributor III

Hi akl,

How do you listen to model changes with your above approach? Traditional model.Validated.bind doesn't work.

Thanks,

Seb.

maniratnagupta
Contributor
Contributor

This discussion helped me a lot can you please tell me what does it mean by '/qHyperCubeDef'.In docs I can get it as 

qPath
string

Path to the definition of the object to be selected. For example, /qHyperCubeDef .

 

but I cant get a gist of it.Can you please explain more on this?

Øystein_Kolsrud
Employee
Employee

@maniratnagupta I've written a blog post on this topic that might be helpful. In particular, check out the "Getting Data" section here:

https://community.qlik.com/t5/Qlik-Design-Blog/Let-s-Dissect-the-Qlik-Engine-API-Part-4-Hypercubes/b...