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);
}
});
Hello anyone is there?
Hello, Bilguun,
Thank you for contacting us.
We suggest checking out the following API calls that allow to operate with events dynamically:
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
Thank you Illia for reply
there is and error
Uncaught TypeError: Cannot read property 'call' of undefined
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
Thank you for reply
as you mention this is fiddle
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
Thank you Illia its working perfect ⭐⭐⭐⭐⭐