How to use my own json object

Stimulsoft Reports.JS discussion
Post Reply
PaPy
Posts: 34
Joined: Fri May 19, 2017 1:51 pm

How to use my own json object

Post by PaPy »

Hi,

I'm newer ! :)

I started using Simulsoft - Reports.js demo and I saw that you use a Json object Demo. (see the image in attachments)

I want to import my own Json object in a different file for example not "Demo.JS" but "myObject.js"

How can I import it and use it in a .mrt file ?
Attachments
demo.PNG
demo.PNG (4.87 KiB) Viewed 11443 times
PaPy
Posts: 34
Joined: Fri May 19, 2017 1:51 pm

Re: How to use my own json object

Post by PaPy »

Up ?
Kubekin Yuriy
Posts: 10
Joined: Wed May 17, 2017 9:24 pm

Re: How to use my own json object

Post by Kubekin Yuriy »

Hello, PaPy.

How are you running your project, from local file or Webserver?

Thank you.
PaPy
Posts: 34
Joined: Fri May 19, 2017 1:51 pm

Re: How to use my own json object

Post by PaPy »

Hi, Kubekin Yuriy.

I am running my project from Webserver using localhost.

I just found by myself how to do, but I had to modify by myself the .mrt file. That is not very "user friendly"...

Is it possible to give a list of different JSON objects to my clients in the "Data Sources" list to allow them to just drag and drop some datas to the report ?
PaPy
Posts: 34
Joined: Fri May 19, 2017 1:51 pm

Re: How to use my own json object

Post by PaPy »

I don't know if I'm clear.

I want to add a database into the .mrt file using javaScript.

For example for the following code (this is a part of my .mrt file) :

Code: Select all

"Dictionary":{
      "DataSources":{
         "0":{
            "Ident":"StiDataTableSource",
            "Name":"databases",
            "Alias":"databases",
            "Columns":{
               "0":{
                  "Name":"libelle",
                  "Index":-1,
                  "NameInSource":"libelle",
                  "Alias":"libelle",
                  "Type":"System.String"
               },
               "1":{
                  "Name":"libcourt",
                  "Index":-1,
                  "NameInSource":"libcourt",
                  "Alias":"libcourt",
                  "Type":"System.String"
               },
               "2":{
                  "Name":"name",
                  "Index":-1,
                  "NameInSource":"name",
                  "Alias":"name",
                  "Type":"System.String"
               }
            },
            "NameInSource":"datas.databases"
         }
This is a table databases with 3 columns :
- libelle ;
- libcourt ;
- name.

And the datas are in a Json object called datas.databases.
Here is the value of the var datas :

Code: Select all

var datas = { "databases" : [{"libelle":"myLibelle1","libcourt":"myLibCourt1","name":"name1"},{"libelle":"myLibelle2","libcourt":"myLibCourt2","name":"name2"}]}
I want to know if is it possible to add databases using javaScript as for example :

Code: Select all

var myObj1 = {JSON};
var myObj2 = {JSON};
var myObj3 = {JSON};

var report = new Stimulsoft.Report.StiReport();
report.loadFile("test.mrt");

report.dictionary.datasources.add(myObj1);
report.dictionary.datasources.add(myObj2);
report.dictionary.datasources.add(myObj3);

report.render();
I have already tried :

Code: Select all

var datas = { "databases" : [{"libelle":"myLibelle1","libcourt":"myLibCourt1","name":"name1"},{"libelle":"myLibelle2","libcourt":"myLibCourt2","name":"name2"}]};
var dataSet = new Stimulsoft.System.Data.DataSet("datas");
var report = new Stimulsoft.Report.StiReport();

report.loadFile("test.mrt");
dataSet.readJson(datas);
report.regData(dataSet.dataSetName, "", dataSet);

report.render();
But it works only if the json object is already defined in the .mrt file. So what is the syntax I have to used to defined my json object in the .mrt file ?
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: How to use my own json object

Post by Alex K. »

Hello,

You can provide your data to the report before running the designer with RegData() method:
dataSet.readJson(datas);
report.regData(dataSet.dataSetName, "", dataSet);
report.dictionary.synchronize();

https://www.stimulsoft.com/en/documenta ... g_data.htm

Thank you.
PaPy
Posts: 34
Joined: Fri May 19, 2017 1:51 pm

Re: How to use my own json object

Post by PaPy »

Here is what the customer should see if the .mrt file do not have dataSources defined, this should be added by javaScript before render the report.
Here is what the customer should see if the .mrt file do not have dataSources defined, this should be added by javaScript before render the report.
what_I_Want.png (101.52 KiB) Viewed 11427 times
Thanks for the answer.

But I already tried this. It works only if in my .mrt file I have defined an object datas. But imagine my report is an empty .mrt, without Databases defined.

What I want, is something like the picture in attachment. That is to say a .mrt file without data sources on wich I add my datas Sources using javaScript to have this view.

Because when I try

Code: Select all

dataSet.readJson(datas);
report.regData(dataSet.dataSetName, "", dataSet);
report.dictionary.synchronize();
It works only if my data source is defined in my .mrt file.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: How to use my own json object

Post by Alex K. »

Hello,

Sorry, maybe we did not exactly understand your question. Could you explain your issue in more details?

We have checked your code and it works correctly.

Thank you.
Attachments
Capture.PNG
Capture.PNG (90.55 KiB) Viewed 11422 times
PaPy
Posts: 34
Joined: Fri May 19, 2017 1:51 pm

Re: How to use my own json object

Post by PaPy »

My bad,

I thought about add a new JSON databases but it's useless because I have already one I just have to add new tables. I think that's why it didn't working.

Thanks for your help ! That was exactly what I needed. I had misunderstand how works .mrt files and the importance of the report.dictionary.synchronize(); which was not in this page : https://www.stimulsoft.com/en/documenta ... g_data.htm

Sorry.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: How to use my own json object

Post by Alex K. »

Hello,

We are always glad to help you.
Please let us know if have any additional questions.

Thank you.
Post Reply