🍉 Meet Flexmonster Pivot Table & Charts 2.9.Check out all the hot features!
Get Free Trial

JS Error in loading pivot without a report and then using setReport() call

Sujit Basu asked on April 29, 2018

Currently we use the following sequence to load Pivot.

  • First a Pivot is loaded (using Angular 2 directive) without a report definition
  • Next setReport() method is used to load data into Pivot. At this time the Slice object has empty filters, rows, etc.
  • Then we apply a manipulate the Slice object and use this with the getData() method to generate charts data.

While doing this at the first call after setReport() we see this error:
flexmonster.js:9 Uncaught TypeError: Cannot read property ‘pages’ of undefined
at L7.select (flexmonster.js:9)
at L7.filter (flexmonster.js:9)
at k4.refresh (flexmonster.js:9)
at a.Rt (flexmonster.js:9)
at a.k1.uG (flexmonster.js:9)
at flexmonster.js:9
We are using the 2.4.x version. Any immediate help would be highly appreciated.

3 answers

Dmytro Zvazhii Dmytro Zvazhii Flexmonster April 30, 2018

Hello Sujit, 
Thank you for your question. Please note that when you want to use a sequence of Flexmonster’s methods you need to be sure that the structure is loaded and the component is ready to answer the requests. In such case, we recommend using Flexmonster’s events such as “reportcomplete”. This event means that the component is initialized and ready to perform other operations. Here is the example of how to use “ready” event: https://www.flexmonster.com/doc/integration-with-angular-2/.  In your case the handler will look the following way:
function onReportComplete() {
      flexmonster.on("reportcomplete", function() {                                              flexmonster.off("reportcomplete");
            flexmonster.on("reportcomplete", function() {
                  flexmonster.getData(...); // getting the data
            flexmonster.setSlice({...}); //setting slice
      flexmonster.setReport({...}); // setting report

The code above describes the general idea and can be optimized. Please find more information about on() and off() methods here: https://www.flexmonster.com/api/on/, https://www.flexmonster.com/api/off/. Also, we recommend considering the idea of combining the steps for pivot loading in one step since it looks a little bit excessive.
Please let us know if it solves the case.

Sujit Basu May 18, 2018

Is there a setSlice() method as you mentioned above. This will come very handy as we are trying to do the following:

  1. Change the grid to display flat data by using setOptions
  2. We would like to set a custom Slice 
  3. We would like to set filters on the slice using setFilter()
  4. We would like to use getData() with a custom prepareData function to get Flat Table data in JS format

However, the setSlice() seems to be a non-supported method. What would be the best way to set a lice before setting the filters – and without using setReport().

Tanya Gryshko Tanya Gryshko Flexmonster May 18, 2018

Hello, Sujit,
Thank you for your reply.
We can suggest you runQuery() method which allows setting the custom slice. For more details and example please refer to our docs: runQuery.
Please let me know if you have other questions.

Please login or Register to Submit Answer