<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>ActiveReportsJS sample</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="stylesheet"
href="https://cdn.materialdesignicons.com/2.8.94/css/materialdesignicons.min.css"
/>
<script src="/activereportsjs/demos/arjs/dist/ar-js-core.js"></script>
<script src="/activereportsjs/demos/arjs/dist/ar-js-viewer.js"></script>
<script src="/activereportsjs/demos/arjs/dist/ar-js-pdf.js"></script>
<script src="/activereportsjs/demos/arjs/dist/ar-js-xlsx.js"></script>
<script src="/activereportsjs/demos/arjs/dist/ar-js-html.js"></script>
<script src="/activereportsjs/demos/arjs-localization/dist/ar-js-locales.js"></script>
<script src="$DEMOROOT$/lib/purejs/license.js"></script>
<link
href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&display=swap"
rel="stylesheet"
/>
<link
rel="stylesheet"
type="text/css"
href="/activereportsjs/demos/arjs/styles/ar-js-ui.css"
/>
<link
rel="stylesheet"
type="text/css"
href="/activereportsjs/demos/arjs/styles/ar-js-viewer.css"
/>
<style>
#viewer-host {
margin: 0 auto;
width: 100%;
height: 500px;
}
</style>
</head>
<body onload="onLoad()">
<div id="viewer-host"></div>
<script>
async function loadData() {
//使用Fetch Api提取数据 https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
const headers = new Headers();
const dataRequest = new Request(
"https://demodata-jp.grapecity.com/northwind/api/v1/Customers",
{
headers: headers,
}
);
const response = await fetch(dataRequest);
const data = await response.json();
return data;
}
async function loadReport() {
//从文件加载定义报表
const reportResponse = await fetch(
"/activereportsjs/demos/resource/reports/CustomersTable.rdlx-json"
);
const report = await reportResponse.json();
return report;
}
async function onLoad() {
const viewer = new ActiveReports.Viewer("#viewer-host", {
language: "zh",
});
const data = await loadData();
const report = await loadReport();
//更新嵌入的数据
report.DataSources[0].ConnectionProperties.ConnectString =
"jsondata=" + JSON.stringify(data);
viewer.open(report);
}
</script>
</body>
</html>