Detailed tutorial of using stimulsoft.reports.js with vue-cli

Detailed tutorial of using stimulsoft.reports.js with vue-cli

vue-cli uses stimulsoft.reports.js (nanny-level tutorial)

Part 1: Data Source Preparation

Here is a tutorial for JSON data

insert image description here

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

JSON data structure

{
	"Data Source Name":[
		// ...data list ]
}

Your own test JSON data

{
    "data": [
        {
            "a": "I am A",
            "b": "I am B",
            "c": "I am C"
        },
        {
            "a": "I am A",
            "b": "I am B",
            "c": "I am C"
        },
        {
            "a": "I am A",
            "b": "I am B",
            "c": "I am C"
        }
    ]
}

Attached is the official data (I deleted some data so that readers can better understand the structure)

{
	"Customers": [{
		"CustomerID": "ALFKI",
		"CompanyName": "Alfreds Futterkiste",
		"ContactName": "Maria Anders",
		"ContactTitle": "Sales Representative",
		"Address": "Obere Str. 57",
		"City": "Berlin",
		"Region": null,
		"PostalCode": "12209",
		"Country": "Germany",
		"Phone": "030-0074321",
		"Fax": "030-0076545"
	}, {
		"CustomerID": "ANATR",
		"CompanyName": "Ana Trujillo Emparedados and Helpers",
		"ContactName": "Ana Trujillo",
		"ContactTitle": "Owner",
		"Address": "Avda. de la Constitución 2222",
		"City": "México DF",
		"Region": null,
		"PostalCode": "05021",
		"Country": "Mexico",
		"Phone": "(5) 555-4729",
		"Fax": "(5) 555-3745"
	}]
}

Part 2: vue-cli introduces stimulsoft.reports.js

insert image description here
insert image description here

Attached is the App.vue code <br /> There are functional tests for displaying data, printing data, saving data, and importing json data

<template>
  <div id="app">
    <div>
      <h2>Stimulsoft Reports.JS Viewer</h2>
      <button @click="print">Print</button>
      <button @click="save">Save</button>
      <button @click="setJson">Set JSON</button>
      <div id="viewer"></div>
    </div>
  </div>
</template>

<script>
export default {
  name: "app",
  data() {
    return {};
  },
    // Load the official sample template code mounted: function () {
    console.log("Loading viewer view");
    // Toolbar console.log("Create a report viewer with default options");
    var viewer = new window.Stimulsoft.Viewer.StiViewer(
      null,
      "StiViewer",
      false
    );

    // Report console.log("Create a new report instance");
    var report = new window.Stimulsoft.Report.StiReport();

    // Load file console.log("Load report from url");
    report.loadFile("/reports/SimpleList.mrt");

    // Create report console.log("Assign the report to the viewer. The report will be automatically generated after the viewer is rendered");
    viewer.report = report;

    // Inject tag console.log("Rendering viewer to selected element");
    viewer.renderHtml("viewer");

    console.log("Loading completed successfully!");
  },
  methods: {
    //Call the printer to print data print() {
      var report = new window.Stimulsoft.Report.StiReport();
      report.loadFile("/reports/SimpleList.mrt");
      report.print();
    },
    // Export and save data save() {
      var report = new window.Stimulsoft.Report.StiReport();
      report.loadFile("/reports/SimpleList.mrt");
      // Save the rendered report as a JSON string var json = report.saveDocumentToJsonString();
      console.log("json", json);
      // Get the report file name var fileName = report.reportAlias
        ? report.reportAlias
        : report.reportName;
      console.log("report.reportName", report.reportName);
      console.log("report.reportAlias", report.reportAlias);
      console.log("fileName", fileName);
      // Save the data to the file window.Stimulsoft.System.StiObject.saveAs(
        json,
        fileName + ".mdc",
        "application/json;charset=utf-8"
      );
    },
    // Get json data and write it to the page setJson() {
      var report = new window.Stimulsoft.Report.StiReport();

      // report.loadFile("/reports/SimpleList.mrt");// Official data template report.loadFile("/reports/Test.mrt");// Your own data template// Create a new DataSet object var dataSet = new window.Stimulsoft.System.Data.DataSet("JSON");
      // Load the JSON data file from the specified URL to the DataSet object // dataSet.readJsonFile("/reports/Demo.json"); //Official data dataSet.readJsonFile("/reports/Test.json"); // Your own json data // The file is imported using the readJsonFile method above, and the interface network request is imported using the following method // let json=/*Data request is omitted here*/
      // dataSet.readJson(JSON.stringify(json));
        
      // Clear the data in the report template report.dictionary.databases.clear();
        
      // Register data set object report.regData("JSON", "JSON", dataSet);
        
      // Render the report using the registration data // report.render();
      // Toolbar var viewer = new window.Stimulsoft.Viewer.StiViewer(
        null,
        "StiViewer",
        false
      );
      // Create report viewer.report = report;
      //Inject tag viewer.renderHtml("viewer");
    },
  },
};
</script>

<style>
</style>

Finally, attach my test project link

Project link: https://pan.baidu.com/s/1HahzqHgFXvHT6OuE4IqzgQ

Extraction code: vr57

Tool Links

Link: https://pan.baidu.com/s/1374m-kCBZBeOdlDrAbXtbQ

Extraction code: dfkc

Official tutorial link
https://www.evget.com/serializedetail/510

This is the end of this article about vue-cli using stimulsoft.reports.js. For more relevant content about vue-cli using stimulsoft.reports.js, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

<<:  How to reference jQuery in a web page

>>:  MySQL tutorial data definition language DDL example detailed explanation

Recommend

Sharing some details about MySQL indexes

A few days ago, a colleague asked me a question a...

Detailed explanation of VUE's data proxy and events

Table of contents Review of Object.defineProperty...

How to deploy nginx with Docker and modify the configuration file

Deploy nginx with docker, it's so simple Just...

How to build a complete samba server in Linux (centos version)

Preface smb is the name of a protocol that can be...

How to use physics engine joints in CocosCreator

Table of contents mousejoint mouse joint distance...

Vue implements local storage add, delete and modify functions

This article example shares the specific code of ...

How to update Ubuntu 20.04 LTS on Windows 10

April 23, 2020, Today, Ubuntu 20.04 on Windows al...

How to install nginx on win10

Because the company asked me to build a WebServic...

How to set default value for datetime type in MySQL

I encountered a problem when modifying the defaul...

Analysis of the principle of Nginx using Lua module to implement WAF

Table of contents 1. Background of WAF 2. What is...

Pycharm2017 realizes the connection between python3.6 and mysql

This article shares with you how to connect pytho...

How to import Chinese data into csv in Navicat for SQLite

This article shares with you the specific method ...