ActiveReports 13 新特性(2)——JS Viewer渲染报表
<div class="post-content new-post"><h3 id="-">概述</h3>
<p>ActiveReports 13现在提供基于JavaScript的一种全新的报表渲染方式——JS
Viewer,与原来的Html5 Viewer相比,JS Viewer 具有以下优点:</p>
<ol>
<li>响应式网页设计</li>
<li>适应不同的屏幕尺寸</li>
<li>减少了对其它库的依赖(如jQuery等)</li>
<li>适用于现代Web端的应用框架:Asp.net MVC,Asp.net Core MVC
,HTML5和主要的JavaScript框架,如Angular 和 Vue.js</li>
</ol>
<p>总结了这么多 JS Viewer 的优点,下面让我们一起来使用 JS
Viewer进行报表的渲染吧(文末提供 JS Viewer示例的源码下载)。</p>
<h3 id="js-viewer-">JS Viewer 渲染报表的步骤</h3>
<p>1、首先打开VS并且新建一个 Asp.net Web应用程序,同时 .Net Framework 版本选择
4.6.2</p>
<p><img style="max-width:800px;" src="https://www.grapecity.com.cn/media/0998451afe715ad320fbcf2908ba64fc.png" alt=""></p>
<p>2、选择一个空的项目,然后点击确定</p>
<p><img style="max-width:800px;" src="https://www.grapecity.com.cn/media/58df0c731409f74e133431894ff8d517.png" alt=""></p>
<p>3、在菜单栏中>>选择工具>>NuGet 包管理器>>程序包管理器控制台</p>
<p><img style="max-width:800px;" src="https://www.grapecity.com.cn/media/03d542b754a1d942dc4f1db554598ef3.png" alt=""></p>
<p>4、在程序包管理器的控制台里输入如下的命令:</p>
<pre class="hljs css"><code><code><span class="hljs-selector-tag">install-package</span> <span class="hljs-selector-tag">Microsoft</span><span class="hljs-selector-class">.Owin</span><span class="hljs-selector-class">.Host</span><span class="hljs-selector-class">.SystemWeb</span> –<span class="hljs-selector-tag">Pre</span>
</code></code></pre><p>然后点击“Enter” 按钮,就会在引用中自动添加对应的引用</p>
<p><img style="max-width:800px;" src="https://www.grapecity.com.cn/media/4a183c1e864c6b86dd6417ddad35718c.png" alt=""></p>
<p>5、在项目中,添加新建项,在新建项的选择栏中选择>>OWIN Startup Class</p>
<p><img style="max-width:800px;" src="https://www.grapecity.com.cn/media/4521bf85a978ce80e0dfbcd4fd7afc21.png" alt=""></p>
<p>6、添加引用</p>
<p><img style="max-width:800px;" src="https://www.grapecity.com.cn/media/faeb711b209a8ff74bf60d7abab29a5e.png" alt=""></p>
<p>7、引用的具体路径:C:\Program Files (x86)\Common
Files\GrapeCity\ActiveReports 13 ,选择
GrapeCity.ActiveReports.Aspnet.Viewer.dll 的引用添加到项目中</p>
<p><img style="max-width:800px;" src="https://www.grapecity.com.cn/media/8d3a979a5d4ba4463ac41746a6f87ff8.png" alt=""></p>
<p>8、复制 Web.Config 文件,然后替换项目中已经存在的Web.Config
文件,Web.Config的路径:</p>
<pre class="hljs"><code><code>C:\\Program Files (x86)\\GrapeCity\\ActiveReports 13\\Deployment\\JSViewer
</code></code></pre><p>注意点:移除 Web.Config 中的</p>
<pre class="hljs javascript"><code><code class="lang-html"><handlers>
<span class="xml"><span class="hljs-tag"><<span class="hljs-name">add</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"nostaticfile"</span> <span class="hljs-attr">path</span>=<span class="hljs-string">"*"</span> <span class="hljs-attr">verb</span>=<span class="hljs-string">"GET"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"System.Web.Handlers.TransferRequestHandler"</span> <span class="hljs-attr">preCondition</span>=<span class="hljs-string">"integratedMode,runtimeVersionv4.0"</span> /></span>
<span class="hljs-tag"></<span class="hljs-name">handlers</span>></span></span>
</code></code></pre>
<p>9、添加和配置报告中间件,例如:</p>
<p><img style="max-width:800px;" src="https://www.grapecity.com.cn/media/11406c07e9f9c045154da55deff376fc.png" alt=""></p>
<p>10、中添加一个新的 HtmlPage1.html</p>
<p>11、在 Scripts 文件夹下添加 JS Viewer 对应的 JS 和 CSS 文件</p>
<p>12、JS和CSS文件的路径如下:C:\Program Files (x86)\GrapeCity\ActiveReports13\Deployment\JSViewer</p>
<p>13、复制 jsViewer.min.js 和 jsViewer.min.css 文件到 ‘scripts’ 文件夹下</p>
<p>14、 在新建的 HtmlPage1.html的 添加如下代码:</p>
<pre class="hljs xml"><code><code class="lang-html"><span class="hljs-meta"><!DOCTYPE html></span>
<span class="hljs-tag"><<span class="hljs-name">html</span>></span>
<span class="hljs-tag"><<span class="hljs-name">head</span>></span>
<span class="hljs-tag"><<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"utf-8"</span> /></span>
<span class="hljs-tag"><<span class="hljs-name">title</span>></span><span class="hljs-tag"></<span class="hljs-name">title</span>></span>
<span class="hljs-comment"><!--Add the references to these files to the target HTML page--></span>
<span class="hljs-tag"><<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://cdn.materialdesignicons.com/2.4.85/css/materialdesignicons.min.css"</span>></span>
<span class="hljs-tag"><<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://fonts.cat.net/css?family=Open+Sans:400,300,600,700"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/css"</span>></span>
<span class="hljs-tag"><<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"scripts/jsViewer.min.css"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/css"</span>></span>
<span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"scripts/jsViewer.min.js"</span>></span><span class="undefined"></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span>
<span class="hljs-tag"></<span class="hljs-name">head</span>></span>
<span class="hljs-tag"><<span class="hljs-name">body</span>></span>
<span class="hljs-comment"><!--Add the DIV element that will contain the JSViewer in the target HTML page--></span>
<span class="hljs-tag"><<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">theme-default</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"viewerContainer"</span>></span>Loading Report<span class="hljs-tag"></<span class="hljs-name">div</span>></span>
<span class="hljs-tag"></<span class="hljs-name">body</span>></span>
<span class="hljs-tag"></<span class="hljs-name">html</span>></span>
<span class="hljs-comment"><!--Add the code that initializes and passes the parameters in the JSViewer instance. The code might vary depending on the technology used to develop the JSViewer component. The example of code for the pure javascript component:--></span>
<span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/javascript"</span>></span><span class="javascript">
<span class="hljs-keyword">var</span> viewer = GrapeCity.ActiveReports.JSViewer.create({
<span class="hljs-attr">element</span>: <span class="hljs-string">'#viewerContainer'</span>,
<span class="hljs-attr">reportID</span>: <span class="hljs-string">'ReportName.rdlx'</span>, <span class="hljs-comment">// the id of the report to display</span>
availableExports: [<span class="hljs-string">'Xml'</span>, <span class="hljs-string">'Pdf'</span>, <span class="hljs-string">'Excel'</span>],
<span class="hljs-attr">reportService</span>: {}
<span class="hljs-comment">// other properties</span>
});
</span><span class="hljs-tag"></<span class="hljs-name">script</span>></span>
</code></code></pre>
<p>15、 报表运行结果如下:</p>
<p><img style="max-width:800px;" src="https://www.grapecity.com.cn/media/5d950ebc8a6a81b5a61c36296e242a01.png" alt=""></p>
<h3 id="js-viewer-">JS Viewer示例的源码</h3>
<p>>><strong><a href="http://www.grapecity.com.cn/downloads/demo/JSViewerSample.zip">点击获取 JSViewer 示例源码</a></strong></p>
<h3 id="-activereports-13-">更多ActiveReports 13 新特性:</h3>
<ol>
<li><a href="https://www.grapecity.com.cn/blogs/activereports-v13-pro-report-designer-for-web">ActiveReports 13
新特性(1)——Web端在线报表设计器</a></li>
<li><a href="https://www.grapecity.com.cn/blogs/activereports-v13-js-report-viewer">ActiveReports 13 新特性(2)——JS
Viewer渲染报表</a></li>
<li><a href="https://www.grapecity.com.cn/blogs/activereports-v13-new-report-chart">ActiveReports 13
新特性(3)——全新的图表控件</a></li>
<li><a href="https://www.grapecity.com.cn/blogs/activereports-v13-rdlx-reports-converted-to-page-reports">ActiveReports 13
新特性(4)——区域报表直接转换为页面报表</a></li>
<li><a href="https://www.grapecity.com.cn/blogs/activereports-v13-automatic-merge-of-cells">ActiveReports 13
新特性(5)——单元格的自动合并</a></li>
<li><a href="https://www.grapecity.com.cn/blogs/activereports-v13-improvement-of-rich-text-box">ActiveReports 13
新特性(6)——富文本框的改进</a></li>
<li><a href="https://www.grapecity.com.cn/blogs/activereports-v13-strengthening-of-regional-reporting-rich-text-box">ActiveReports 13 新特性(7)——区域报表 富文本框
的加强</a></li>
</ol>
</div>
页:
[1]