原創|使用教程|編輯:鄭恭琳|2019-10-31 15:24:02.287|閱讀 283 次
概述:本示例說明如何在查看器中顯示具有交互作用的報表。報表可以使用不同的交互方式,例如排序、折疊、下鉆。報表還可以包含用戶要求的參數。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
立即點擊下載Stimulsoft Reports.Net最新版
本示例說明如何在查看器中顯示具有交互作用的報表。報表可以使用不同的交互方式,例如排序、折疊、下鉆。報表還可以包含用戶要求的參數。
首先,您需要將StiMvcViewer組件添加到視圖頁面。您還需要將StiMvcViewerOptions對象傳遞給構造函數。所需的最少選項是兩個操作-GetReport和ViewerEvent,它們位于操作“Actions”選項組中。
@using Stimulsoft.Report.Mvc; ... @Html.Stimulsoft().StiMvcViewer(new StiMvcViewerOptions() { Actions = { GetReport = "GetReport", ViewerEvent = "ViewerEvent" } })
為了演示不同類型的交互式報表,請在網頁上添加鏈接。使用鏈接中的id參數報表定義。
<table> <tr> <td class="reports" valign="top"> <div style="width: 180px;"> @Html.ActionLink("Sorting", "Index", new { id = "1" }) <br />Report with dynamic sorting <br /><br /> @Html.ActionLink("List Of Products", "Index", new { id = "2" }) <br />Report with drill down <br /><br /> @Html.ActionLink("Group With Collapsing", "Index", new { id = "3" }) <br />Report with collapsing <br /><br /> @Html.ActionLink("Master Detail", "Index", new { id = "4" }) <br />Report with bookmarks <br /><br /> @Html.ActionLink("Selecting Country", "Index", new { id = "5" }) <br />Report with parameters </div> </td> <td style="width: 100%;" valign="top"> @Html.Stimulsoft().StiMvcViewer(new StiMvcViewerOptions() { Actions = { GetReport = "GetReport", ViewerEvent = "ViewerEvent" } }) </td> </tr> </table>
在上面的選項中,我們定義了兩個動作,我們需要將其添加到控制器中。
GetReport操作根據URL的id參數加載報表,并使用GetReportResult()靜態方法將答案返回給查看器的客戶端部分。在此方法的參數中,應傳遞報表對象。
public ActionResult GetReport(int? id) { // Create the report object StiReport report = new StiReport(); switch (id) { // Dynamic sorting case 1: report.Load(Server.MapPath("~/Content/Reports/DrillDownSorting.mrt")); break; // Drill down case 2: report.Load(Server.MapPath("~/Content/Reports/DrillDownListOfProducts.mrt")); break; // Collapsing case 3: report.Load(Server.MapPath("~/Content/Reports/DrillDownGroupWithCollapsing.mrt")); break; // Bookmarks case 4: report = new StiMasterDetail(); break; // Parameters case 5: report = new StiParametersSelectingCountryReport(); break; default: report.Load(Server.MapPath("~/Content/Reports/DrillDownSorting.mrt")); break; } // Load data from XML file for report template DataSet data = new DataSet("Demo"); data.ReadXml(Server.MapPath("~/Content/Data/Demo.xml")); report.Dictionary.Databases.Clear(); report.RegData(data); return StiMvcViewer.GetReportResult(report); }
ViewerEvent操作處理所有查看器事件(切換頁面、縮放、打印、導出、交互等),并使用ViewerEventResult()靜態方法將答案返回給客戶端。
public ActionResult ViewerEvent() { return StiMvcViewer.ViewerEventResult(); }
在下面的屏幕截圖中,您可以看到示例代碼的結果。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn