发布时间 : 2019-10-31 15:24:02.287|阅读 297 次
概述:本示例说明如何在查看器中显示具有交互作用的报表。报表可以使用不同的交互方式,例如排序、折叠、下钻。报表还可以包含用户要求的参数。
相关链接:
立即点击下载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();
}在下面的屏幕截图中,您可以看到示例代码的结果。

渝ICP备12000582号-15/渝公网安备 50010702501010号