ilich / MvcReportViewer

ASP.NET MVC Html Helpers for ReportViewer Control.
MIT License
280 stars 131 forks source link

SizeToReportContent parameter #145

Open lpawlak opened 8 years ago

lpawlak commented 8 years ago

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.

ilich commented 8 years ago

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 :-)) .

lpawlak commented 8 years ago

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: mvcreportviewer_1 In reportviewerformvc it's look better because the page height and weigh is fit to report content: reportviewerformvc_1

ilich commented 8 years ago

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.

lpawlak commented 8 years ago

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&amp;_m=Remote&amp;_r=%2fRaporty%2fDODATKI+SPEED%2fpaczki_web&amp;_16=True&amp;_18=True&amp;_34=True&amp;_35=True&amp;_36=100%25&amp;_37=440px&amp;_39=450px&amp;UsrId=1" scrolling="no"></iframe>
ilich commented 8 years ago

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.

ilich commented 8 years ago

I hope it will help you with your project.

lpawlak commented 8 years ago

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: iframe

But horizontal scroll-bar disappear after I set iframe width to 2681px. Maybe it's because data load asynchronously?

ilich commented 8 years ago

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.

lpawlak commented 8 years ago

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);
        }
ilich commented 8 years ago

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.

ilich commented 8 years ago

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.

lpawlak commented 8 years ago

And that's why I will stay in your solution - it's more flexible and powerful. I will wait for the new next version.

nhaberl commented 7 years ago

Any news here? We would like to fit the report into the parent container without the need for scrolling.

martindlarsson commented 7 years ago

I second that!