MvcReportViewer
MvcReportViewer copied to clipboard
SizeToReportContent parameter
Is there any chance to add option to "SizeToReportContent" ? I have checked similar lib from https://reportviewerformvc.codeplex.com/ and there is this option. Report sized to comtent looks better (there is no ugly scrollbars) and there is better printing direct from browser.
SizeToReportContent option is supported. You should use ControlSettings class to configure all ReportViewer options. Please take a look to https://github.com/ilich/MvcReportViewer/blob/master/MvcReportViewerExample/Views/Home/Fluent.cshtml example. Please let me know if you will find a bug using SizeToReportContent option from the library (all other bugs are welcome as well :-)) .
I am now using fluent view, but it's not working as I expect.
Please see screen called "mvcreportviewer_1" - it's MvcReportViewer report with flame with scrolling bar because content is much longer than window:
In reportviewerformvc it's look better because the page height and weigh is fit to report content:
I think the difference is in the parameters mvcreportviewer and reportviewermvc are passing to hosting iframe. Please check the difference in iframe tag and then pass proper iframe attributes to mvcreportviewer. You can pass iframe attributes using Attributes(object htmlAttributes) from the fluent interface.
Please see HTML source of report generated by reportviewerformvc :
<iframe frameborder="0" src="/ReportViewerWebForm.aspx" scrolling="no" id="r484e4831-5287-4065-a811-a79ec1ee4ecc" style="min-height: 480px ! important; height: 1160px; width: 2212px;">iframes not supported.</iframe>
I think, that there is magic script in JS that measure report content. Source of report generated by MvcReportViewer:
<iframe width="100%" height="470" frameborder="0" style="border: none" src="/MvcReportViewer.aspx?_id=f4aa5528-f32a-4234-ad51-7804f8166f33&_m=Remote&_r=%2fRaporty%2fDODATKI+SPEED%2fpaczki_web&_16=True&_18=True&_34=True&_35=True&_36=100%25&_37=440px&_39=450px&UsrId=1" scrolling="no"></iframe>
I think reportviewerformvc makes your report "full screen" using window.innerHeight information. You can do the same with MvcReportViewer:
@Html.MvcReportViewerFluent("App_Data/Reports/Cities.rdlc").ProcessingMode(ProcessingMode.Local).LocalDataSource("Cities", Model.FilteredCities).Attributes(new { Height = 150, Width = "100%", style = "border: 2px solid", id="my-report" })
<script>
$(document).ready(function () {
var height = window.innerHeight - 455;
$("#my-report").height(height);
});
</script>
455px is your header height.
I hope it will help you with your project.
I'm afraid it's not good solution for my project. In your example you have loaded data after page load. In my scenario on page load where is empty report with 2 controls to select date range and after I click "View Report" a get rows with are longer than browser width.
I have saw interesting thing that calculated width of ReportViewer div (inside iframe) is 1520px:
But horizontal scroll-bar disappear after I set iframe width to 2681px. Maybe it's because data load asynchronously?
Yes, it might be because of asynchronous rendering. Set AsyncRendering to false in control settings and try again. 1520px is calculated by MS control itself.
If AsyncRendering does not help, please try to reverse engineer reportviewerformvc. There might be something set on the background which I am not aware of.
After set AsyncRendering to false the same situation, so it's not a solution. I think that this script from https://reportviewerformvc.codeplex.com/SourceControl/latest#Trunk/ReportViewerForMvc/Scripts/ReceiveMessage.js is do correct width, but I don't know how to use this code after content loaded or button "View Report" is clicked:
var resizeIframe = function (msg) {
var height = msg.source.document.body.scrollHeight;
var width = msg.source.document.body.scrollWidth;
$(ReportViewerForMvc.getIframeId()).height(height);
$(ReportViewerForMvc.getIframeId()).width(width);
}
I reviewed their code. This is an interesting solution. I think I will add it to the next version once I will have time. Thank you for the idea.
But there is one problem with their code. If you use it it will overwrite height and width you provided to MvcReportViewer call in Razor. It might be a broken change for others. I will have to think how to do it nicer.
And that's why I will stay in your solution - it's more flexible and powerful. I will wait for the new next version.
Any news here? We would like to fit the report into the parent container without the need for scrolling.
I second that!