Declaring a JSON model for designer with custom captions

Stimulsoft Reports.JS discussion
Post Reply
paroxit
Posts: 11
Joined: Thu Apr 12, 2018 10:53 am

Declaring a JSON model for designer with custom captions

Post by paroxit »

Hello,

I was able to bind a JSON data to dictionary of the report designer using below code.

Code: Select all


            var designer = new Stimulsoft.Designer.StiDesigner();

                    // Create the report designer with default options and show it in this place
                    var report = new Stimulsoft.Report.StiReport();
                    report.load(designData.designJson);
                    

                    //Dataset created
                    var dataSet = new Stimulsoft.System.Data.DataSet("test");
                    dataSet.readJson(JSON.stringify(designData.designModel));

                    report.regData(dataSet.dataSetName, "Test Data", dataSet);

                    report.dictionary.connect(false);
                    report.dictionary.synchronize();

                    designer.report = report;

                    designer.onSaveReport = function (event) {

                        var jsonStr = event.report.saveToJsonString();

                        var obj = {
                            id : designData.id,
                            name: event.fileName,
                            designJson: jsonStr
                        }

                        $.ajax({
                            url: '/save',
                            method: 'POST',
                            data: JSON.stringify(obj),
                            contentType: 'application/json',
                            dataType: 'json',
                            success: function (data) {
                                if (data.code == 200) {
                                    alert("Ok");
                                }
                            }
                        });

                        event.preventDefault = true;

                    }
                }
            });
However, designer seems to be serializing the keys of JSON and putting a prefix before the keys and then add them into the dictionary. Because when I go into dictionary, I see (i.e.)
- root
- root_products
- code
- id

What I need to do is to define captions for these fields for user to see and understand them correctly. I have written some loops for to change them;

Code: Select all

for (var t = 0; t < dataSet.tables.count; t++) {
                        var _columns = dataSet.tables.getByIndex(t).columns;

                        for (var i = 0; i < _columns.count; i++) {
                            if (_columns.getByIndex(i).caption == "timestamp") {
                                _columns.getByIndex(i).caption = "Date";
                            }
                        }
                    }
Is there any way to bind a JSON model descriptor rather than the JSON data itself ? To accomplish this without going into loops ?
Lech Kulikowski
Posts: 6271
Joined: Tue Mar 20, 2018 5:34 am

Re: Declaring a JSON model for designer with custom captions

Post by Lech Kulikowski »

Hello,

Please send us your JSON data for analysis.

Thank you.
paroxit
Posts: 11
Joined: Thu Apr 12, 2018 10:53 am

Re: Declaring a JSON model for designer with custom captions

Post by paroxit »

Lech Kulikowski
Posts: 6271
Joined: Tue Mar 20, 2018 5:34 am

Re: Declaring a JSON model for designer with custom captions

Post by Lech Kulikowski »

Hello,

Please try to add Name for the top level.

Thank you.
Attachments
Capture.PNG
Capture.PNG (104.68 KiB) Viewed 3044 times
paroxit
Posts: 11
Joined: Thu Apr 12, 2018 10:53 am

Re: Declaring a JSON model for designer with custom captions

Post by paroxit »

Hello,

It would replace the "root" with the given name yes, but still, how will I be able to rename all of the columns under every each one of these tables separately ?

I mean, I want to rename "Data_creator" with just "Creator" and also "Data_creator_realName" with "UserName" ...

I need to change column names (or rather aliases).
Lech Kulikowski
Posts: 6271
Joined: Tue Mar 20, 2018 5:34 am

Re: Declaring a JSON model for designer with custom captions

Post by Lech Kulikowski »

Hello,

Unfortunately, there are no options to make it automatically. You can rename data sources in the dictionary.

Thank you.
Post Reply