How to set report json in to flexmonster.

Answered
Zain Asghar asked on January 20, 2023

I have read the doc about setting the report JSON file to the tool. But in my case, I'm getting a report JSON object from the backend and I need to set it to the tool directly. I don't have JSON file to load report.

10 answers

Public
Maksym Diachenko Maksym Diachenko Flexmonster January 20, 2023

Hello, Zain!

Thank you for writing to us.

Flexmonster allows loading the report from the file system or via URL. It is possible to set the report in the following way:

let pivot = new Flexmonster({
  container: "#pivot-container",
  toolbar: true,
  report: "http://localhost:3000/report"
})

Also, you are welcome to check out the following guide on how to restore the report via code: https://www.flexmonster.com/doc/save-and-restore-report/#restore-report

Please let us know if you found this information helpful.

Best Regards,
Maksym

Public
Zain Asghar January 23, 2023

Ok have read about it but the question is different. I don't have a file system or URL. I am saving the report JSON to the database and in response to the HTTP request I receive Report's JSON object. I need to set that Json to the tool.

Public
Maksym Diachenko Maksym Diachenko Flexmonster January 25, 2023

Hi, Zain!

Thank you for your reply.

It is possible to directly set the report JSON object into the component in the new Flexmonster() constructor if you have loaded it before component initialization. Setting the report object after the component is initialized is possible by using the setReport() API call. You are welcome to check the example: https://jsfiddle.net/flexmonster/L0n1r933/ 
Using these methods may work if you already have the report loaded to the client from the database, and you need to set it to the Flexmonster instance. 

Please let us know if using these methods fits your case.

Best Regards,
Maksym

Public
Maksym Diachenko Maksym Diachenko Flexmonster February 1, 2023

Hello, Zain!

Hope you are doing well.
Our team is wondering if you had time to check our previous answer about setting a JSON object to a report.
Please let us know if it helped you.

Best Regards,
Maksym

Public
Melvin January 15, 2024

Hey Maksym,

Can I get more information on how to set the report via a Json object.
I'm trying this

  public report: Object = {
    dataSource: {
      type: "json",
      data:  this.jsonData,
    }
  }

but I don't get any data.

Public
Maksym Diachenko Maksym Diachenko Flexmonster January 16, 2024

Hi, Melvin!

Thank you for your question.

We recommend following these steps to find the possible reason for this issue:

  1. Open the browser console to see if there are any errors related to Flexmonster.
  2. If you are loading the data asynchronously, ensure the loading is complete when the component is initialized. This can be done by printing this.jsonData into the console before the line containing the new Flexmonster() constructor.
  3. Check if the JSON data is specified in one of the supported formats

Feel free to contact us if further assistance is needed.

Best Regards,
Maksym

Public
Maksym Diachenko Maksym Diachenko Flexmonster January 30, 2024

Hi, Melvin!

Hope you are doing well.
We are wondering if you were able to resolve the issue with loading JSON data into the report.
Looking forward to hearing from you.

Best Regards,
Maksym

Public
Maksym Diachenko Maksym Diachenko Flexmonster February 13, 2024

Hi, Melvin!

Hope you are doing well.
We are wondering if you were able to resolve the issue with loading JSON data into the report.
Looking forward to hearing from you.

Best Regards,
Maksym

Public
Melvin February 13, 2024

Hey Maksym,
Yes it did. However, when I save the file loaded by json from the backend. I'm saving the key values of each column and not the dimensions.
For example if City and Sales are columns on the pivot table, when I save I want to see the slices as
{
    dimensions: "City",
     measure: "Sales"
} and not the data, similar to how the save functions work in the demo " https://www.flexmonster.com/demos/js/pivot-table". Right now I'm getting the actual value of each dimension and measure. 
I also want to add the data source as a key value to json array.

Please let us know how to fix this.

Regards,
Melvin Paul

Maksym Diachenko created a new ticket #60846 from this answer
Public
Maksym Diachenko Maksym Diachenko Flexmonster February 14, 2024

Hello, Melvin!

Thank you for your feedback.
We have addressed your new questions in this ticket: https://www.flexmonster.com/question/how-to-change-the-saved-report-format 

Best Regards,
Maksym

Please login or Register to Submit Answer