Despite the COVID-19 outbreak, our team continues operating at full speed. We are always here to support and answer all your questions.

Feel free to reach out by filling this quick form.

Fill the form
Get Free Trial

How do i turn on pivot reportchange event?

Re-Open
Bilguun asked on October 19, 2020

Hello flexmonster team,
I have an problem with reportchange event
when instance created im just reportchange event turn off then do my job next time will reportchanges cannot accept changes how can i turn on reportchange event?

var pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
report: {
dataSource: {
data: getData()
},
options: {
configuratorActive: false
}
},
reportcomplete:function(){

pivot.off("reportchange");
//do job
},
reportchange:function(){
getchange(id);
}
});

7 answers

Public
Bilguun October 22, 2020

Hello anyone is there?

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster October 23, 2020

Hello, Bilguun,
 
Thank you for contacting us.
 
We suggest checking out the following API calls that allow to operate with events dynamically:

  • on – sets a JS function for the specified event
  • off – removes JS handlers for specified event

 
For example, you can subscribe to the reportchange event after all required actions are finished in the reportcomplete handler:

var pivot = new Flexmonster({
  ...
  reportcomplete: function() {
    //do job
    flexmonster.on("reportchange", function() {
  	  getchange(id);
    })
  }
});

 
Another approach is to initialize the handler separately and manage the subscription dynamically:

var pivot = new Flexmonster({
  ...
  reportcomplete: function() {
  	pivot.off("reportchange", getChange);
    //do job
    pivot.on("reportchange", getChange);
  },
  reportchange: getChange
});

function getChange() {
  getchange(id);
}

 
We hope it works for you.
 
Kind regards,
Illia

Public
Bilguun October 23, 2020

Thank you Illia for reply
there is and error
Uncaught TypeError: Cannot read property ‘call’ of undefined

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster October 26, 2020

Hello, Bilguun,
 
Thank you for your feedback.
 
We want to ask you for a sample where the exception could be observed.
The example would allow us to find the reason for the error and provide you with the solution.
You can use the JSFiddle template to prepare the example where the issue would be reproducible.
 
Our team is looking forward to hearing from you.
 
Regards,
Illia

Public
Bilguun October 27, 2020

Thank you for reply 
as you mention this is fiddle

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster October 29, 2020

Hello, Bilguun,
 
Thank you for providing us with an example.
 
We have modified the JSFiddle to demonstrate the recommended approach.
 
Instead of subscribing to the reportcomplete event within the Flexmonster’s constructor, move the subscription to the set function. Please note that the guid property of the item should be passed to the set function as well:

var pivot = new Flexmonster({
  container: "#" + item.guid,
  ...
  reportcomplete: function() {
    _this.set(pivot, item.conditions, item.formats, item.guid);
  },
  reportchange: function() {
    _this.change(item.guid)
  }
});

 
Next, subscribe to the reportchange function within the set function:

set: function(p, c, f, guid) {
  var _this = this;
  p.off("reportchange");
  if (c != null) {
  c.forEach((item) => {
      p.setCondition(item);
    })
  }
  if (f != null) {
    f.forEach((item) => {
      p.setFormat(item);
    })
  }
  p.on("reportchange", () => {
    _this.change(guid);
  });
}

We have also changed the structure of the conditions so that variables c and f would be independent.
 
Moreover, the structure of the change function must be changed as shown below:

change: function(guid) {
  var _this = this;
  let pivot = _this.pivotCollection.find(item =>
    item.guid == guid
  )
  let layout = _this.layout.find(item =>
    item.guid == guid
  );
  _this.changedLayouts.push(layout);
  _this.changedPivots.push(pivot);
}

In your case, both pivot and layout variables are always undefined because of the function passed to the find method. Besides, rename the changedlayout property to changedLayouts to fit the structure of the _this object.
 
We hope it helps.
 
Regards,
Illia

Public
Bilguun October 30, 2020

Thank you Illia its working perfect ⭐⭐⭐⭐

Please login or Register to Submit Answer