We have updated Flexmonster Software License Agreement, effective as of September 30, 2024. Learn more about what’s changed.

Loading Empty Data Set Breaks Report Definition

Answered
Aaron asked on April 16, 2020

Hi there,
I have a rather pressing issue and I cannot seem to solve it myself. I believe its a bug with Flexmonster and I have reproduced the issue based off your JSON jsfiddle example.
So in our application we have a set of pre-defined reports that a user can load and then edit as much as they want. The user also has the ability to change the parameters for the datasource and reload the updated data.
What I have found is that when you have a report that is fully defined in flexmonster, and you load an empty data set, when I then update the pivotReport with a valid datasource the report definition is lost and you have to setup all the fields and measures and mappings again. This doesnt work for us as the user needs to be able to see the default report that we setup regardless of whether they first loaded it without valid data.
This is reproducible in this jsfiddle. 
https://jsfiddle.net/ryepuzwn/
When you first load the JSFiddle you have a nice looking well defined report. However if you click the button to load an empty dataset you see the empty popup as expected but then when i reload the valid dataset the report reverts to a basic setup and is no longer using the report definition that was initially loaded.
I have also tried to debug this a lot myself and what I can see is that when we call pivot.updateData the report measures and options are all still showing on the pivot object. So the pivot grid component is somehow ignoring it.
Please let me know if I have explained this well enough. The JSFiddle should demonstrate it well enough.
Thanks,
Aaron
PS.
I am using ng-flexmonstrer 2.8.3 and running Angular 9 in my project.

9 answers

Public
Mykhailo Halaida Mykhailo Halaida Flexmonster April 17, 2020

Hi Aaron,
 
Thank you for writing to us.
 
Please note that the slice is built based on the data passed to the pivot table. Therefore, if no data is provided, there is nothing to build a slice upon, but as soon as you pass some data, the slice can be defined.
 
What we would suggest in your situation is to specify a mapping object, which predefines all the fields in your data, thus providing the data structure for the slice to be built on. More specifically, you need to include the mapping object in every updateData() API call, since the latter updates the whole dataSource object erasing the mapping property if it is not specified:
 

function onOpenEmpty() {
pivot.updateData({
type: "json",
data: getNoData(),
mapping: getMapping()
});
}


function getMapping() {
return {
"Country": {
type: "string"
},
"Category": {
type: "string"
},
"Color": {
type: "string"
},
"Price": {
type: "number"
},
"Quantity": {
type: "number"
}
}
}

 
We've prepared a quick JSFiddle example based on your sample, where the hierarchy captions are still displayed with empty data and the slice structure being preserved throughout the data transformations: https://jsfiddle.net/flexmonster/ucsfbg4d
 
Please let us know if this helps.
 
Best regards,
Mykhailo

Public
Aaron April 17, 2020

Hi Mykhailo,
 
Thanks for the amazing turnaround once again. Unfortunately in my case I am not actually using hardcoded json data as per the fiddle and I am already using a mapping object.
 
In my case I am using the following:

this.pivotReport.dataSource = {
type: "json",
fileName: this.baseUrl() + "?parameters=" + params,
requestHeaders: {
"X-LoggedInUser": userToken
},
mapping: this.getMapping()
};

if (this.firstLoad) {
this.pivot.flexmonster.setReport(this.pivotReport);
} else {
this.pivot.flexmonster.updateData(this.pivotReport.dataSource);
}

As you can see above my dataSource already has the mapping object defined and it works great when there is valid data the the first time. But as you can see I only call set report on the first load because a user may have customised the report definition before changing the report parameters and reloading the data. The updateData seems to be ignoring my mapping property of the dataSource.

When I try and call the updateData method in the way you have demonstrated I cannot define the fileName and requestHeaders I can only specify the data directly which I do not have as the flexmonster control handles this in the background.
 
I hope there is some other suggestion you can come up with as the suggestion doesnt seem to work for my particular case.
 
Thanks once again.
Aaron

Public
Mykhailo Halaida Mykhailo Halaida Flexmonster April 23, 2020

Hi Aaron,
 
Thank you for explaining your situation further in detail and our apologies for the delayed response.
 
We would like to emphasize that the object passed to the updateData() API call employs the same structure as the dataSource object from the pivot table report. Therefore, you actually can specify the filename & requestHeaders in updateData() just as you do in the dataSource object when defining the Report object.
 
However, if we understand your situation correctly, a potential solution would involve using the setReport() instead of updateData(). We've prepared another JSFiddle example to illustrate this: https://jsfiddle.net/flexmonster/ym6brqfn/
 
In this sample, the last valid report is stored in a global variable which is updated every time a current report is renewed with valid configurations (that is, not containing empty data). This allows you to use it when you need to reset the report to a valid form after the empty data has been loaded, breaking the slice configurations. We've also added a few small tweaks in order for the hierarchy captions still being displayed even when the data is empty.
 
We hope this helps you solve the mentioned issue.
 
Please let us know your thoughts.
 
Best regards,
Mykhailo

Public
Aaron April 28, 2020

Hi Mykhailo,
Your answer works perfectly for me. Thank you very much for taking the time to come up with an example for me. Much appreciated. This is working like the bomb.
Regards,
Aaron

Public
Aaron May 4, 2020

Hi Mykhailo,
Seems I was a bit hasty in accepting this solution. It works fine if the first call isnt an empty dataset but if you start by choosing parameters that result in an empty dataset and then adjust the parameters to a valid dataset the report definition is not saved in currentReport.
This is unfortunate. Because especially at the start of a new month the default reports get the current months data and often there wont be any data for the initial call to fetch data and only once the user chooses the previous month will there be data.
This is reproducible in your example by loading the empty json data first.
Thanks,
Aaron
 

Public
Mykhailo Halaida Mykhailo Halaida Flexmonster May 5, 2020

Hi Aaron
 
We've tried to reproduce the described behavior and it seems like the browser is now returning an error when the empty data set is loaded first. We will investigate this and return to you with a fix ETA June 1st.
 
Please let us know if we can help you with anything else in the meantime.
 
Kind regards,
Mykhailo

Public
Mykhailo Halaida Mykhailo Halaida Flexmonster June 2, 2020

Hi Aaron,
 
We are glad to announce that the issue with loading empty data was fixed.
 
This is provided in the 2.8.8 version of Flexmonster: https://www.flexmonster.com/release-notes/
You are welcome to update the component. Here is our updating to the latest version tutorial for guidance: https://www.flexmonster.com/doc/updating-to-the-latest-version/ 
 
Please let us know if everything works fine for you.
 
Best regards,
Mykhailo

Public
Aaron June 2, 2020

Thank you Mykhailo, I will update and let you know how it goes.

Public
Aaron June 3, 2020

Hi Mykhailo,
 
Please consider this resolved. You may close the ticket.
 
Much appreciated,
Aaron 

Please login or Register to Submit Answer