How to trigger reportcomplete when all the tables have been loaded

Answered
Bernat Pinós asked on April 5, 2019

Hello,

We have a dashboard in which we load several pivot tables. It's clear that the 'reportcomplete' event is triggered when a table has been loaded an rendered. However, when we're loading the dashboard, there are tables that render faster than others, so when one is rendered, the 'reportcomplete' event is triggered and causes errors because other tables haven't been loaded. Is there a way to call a function when all 'reportcomplete's in the dashboard have been triggered?

Thank you!

4 answers

Public
Dmytro Zvazhii Dmytro Zvazhii Flexmonster April 8, 2019

Hello Bernat,
Thank you for your question. Here is a couple of solutions you can choose from:

  • the first one is to count the reportcomplete dispatchers. As soon as that number equals the number of pivots, you can be sure that everything is successfully loaded.
  • the other approach helps when you need to know exactly which pivot instance has dispatched reportcomplete event. Please see the following JSFiddle example: https://jsfiddle.net/flexmonster/npsz5rck/149/. Each handler calls the same method and passes an appropriate Flexmonster object. In such a way, you can be sure that you are working with the up and running Flexmonster instance.

Please let us know if the information above helped to resolve the case.
Regards,
Dmytro

Public
Bernat Pinós April 9, 2019

Hi Dmytro,
Your second approach fits perfectly with what we need to do. However, you set the pivot table as a variable in the same code, so you can call the object with "pivot1." but we can't because the table is already set in our server. We use the 'reportcomplete' event like this:
flexmonster.on ( 'reportcomplete', function ( event ){ code });

How can we get which table has triggered the event?
Kind regards,
Bernat Pinós

Public
Bernat Pinós April 9, 2019

By the way, is there a way to count how many rows a table has from JavaScript (with jQuery)?

Public
Dmytro Zvazhii Dmytro Zvazhii Flexmonster April 10, 2019

Hello Bernat,
Thank you for your feedback.
Each Flexmonster instance is separated from one another. The flexmonster reference which is stored in DOM has access only to the last created instance. Therefore, if you work with multiple Flexmonster instances on the page you need to take care of storing the references on your own. In such case, when multiple objects are created each of them should be stored in a separate variable.
As for counting table rows, it is not possible to achieve using jQuery and DOM since Flexmonster has a virtual grid and it does not render all the view at once. Currently, there is no API call which allows getting the number of rows.
Please let us know in case of any other question.
Regards,
Dmytro

Please login or Register to Submit Answer