Asp.net mvc MVC中的SSRS Reportviewer,通过自动调整iframe的大小以适应报告来删除iframe滚动条
我已经拼凑了有关在iframe中呈现reportviewer时取消iframe滚动条而代之以浏览器滚动条的信息。MVC不支持在视图中呈现报表查看器,因此需要iframe 编辑:我很难找到这个解决方案(如下),因此我想我会与大家分享Asp.net mvc MVC中的SSRS Reportviewer,通过自动调整iframe的大小以适应报告来删除iframe滚动条,asp.net-mvc,reportviewer,ssrs-2008-r2,Asp.net Mvc,Reportviewer,Ssrs 2008 R2,我已经拼凑了有关在iframe中呈现reportviewer时取消iframe滚动条而代之以浏览器滚动条的信息。MVC不支持在视图中呈现报表查看器,因此需要iframe 编辑:我很难找到这个解决方案(如下),因此我想我会与大家分享 在aspx页面中(将在iframe中呈现的页面) 使用中的一组扩展解决了类似的问题 -也许有人能帮忙 $(function () {//jQuery document.ready // attach an event handler, whenever a
在aspx页面中(将在iframe中呈现的页面)
使用中的一组扩展解决了类似的问题 -也许有人能帮忙
$(function () {//jQuery document.ready
// attach an event handler, whenever a 'property' of the reportviewer changes, the function will be called to adjust the height of the iframe
Sys.Application.add_load(function () {
$find("ReportViewer").add_propertyChanged(viewerPropertyChanged); // $.find("ReportViewer") will return the reportviewer with id "ReportViewer"
});
function adjustIframeSize() {
// you can play around with these figures until your report is perfect
var extraHeightToAvoidCuttingOffPartOfReport = 100;
var extraWidthToAvoidCuttingOffPartOfReport = 10;
// '#ReportViewer_fixedTable' is a portion of the report viewer that contains the actual report, minus the parameters etc
var reportPage = $('#ReportViewer_fixedTable');
// get the height of the report. '#ParametersRowReportViewer' is that top part that contains parameters etc
var newHeight = reportPage.height() + $('#ParametersRowReportViewer').height() + extraHeightToAvoidCuttingOffPartOfReport;
// same for width
var newWidth = reportPage.width() + extraWidthToAvoidCuttingOffPartOfReport;
// get iframe from parent document, the rest of this function only works if both the iframe and the parent page are on the same domain
var reportIframe = $('#ReportViewerFrame', parent.document);
// just make sure that nothing went wrong with the calculations, other wise the entire report could be given a very small value for height and width, thereby hiding the report
if(newHeight>extraHeightToAvoidCuttingOffPartOfReport)
reportIframe.height(newHeight);
if (newWidth > extraWidthToAvoidCuttingOffPartOfReport)
reportIframe.width(newWidth);
}
function viewerPropertyChanged(sender, e) {
// only change the iframe dimensions when 'isLoading'
if (e.get_propertyName() == "isLoading") {
if (!$find("ReportViewer").get_isLoading()) {
adjustIframeSize();
}
}
};
});
@Html.ReportViewer(
ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer,
new { scrolling = "no" })