This is a migrated thread and some comments may be shown as answers.

To add Filters in Q2016 reporting

3 Answers 121 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Obulesh
Top achievements
Rank 1
Obulesh asked on 28 Apr 2016, 06:24 AM

Hi Team,

               I am unable to filter the report content using a external combo box. Is there any way to add filters to report. I have seen the Report Book for example but unable to enable the filter toggle in the report. If there is any demo for that Please let me know.

3 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 03 May 2016, 08:14 AM
Hello Obulesh,

Telerik Reporting viewers have parameters area which are displayed if reports have visible report parameters. You can also use a custom UI, that updates the viewer's ReportSource's Parameters collection which is transferred and mapped by key to the wrapped report's ReportParameters collection - Report Sources.

Telerik Reporting installer adds local examples installed by default under C:\Program Files (x86)\Telerik\Reporting Q1 2016\Examples, where you can check the settings of reports with parameters.


I hope this information is helpful.

Regards,
Stef
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Obulesh
Top achievements
Rank 1
answered on 04 May 2016, 05:45 AM

Hi Stef,

                      Below is the code i'm trying to have a custom search filter and accordingly search the Data in report.

 

I have taken a controller and adding the List to Entity Data Source, as we are using Entity data source.

 

 

Controller: -  

public ActionResult MiscellaneousReportViewer(string type)
        {
            MiscellaneousViewModel vm = new MiscellaneousViewModel();


            ViewBag.Title = "Miscellaneous Master Report";

            ARCDbContext dbContext = new ARCDbContext();

            List<MiscellaneousViewModel> lstData = MiscellaneousViewModel.SeachMisc(type);

            try
            {
                Telerik.Reporting.EntityDataSource entityDataSource = new Telerik.Reporting.EntityDataSource();

                entityDataSource.Context = lstData;
                entityDataSource.ContextMember = "Miscellaneous";
                
                Telerik.Reporting.Report rpt = new Telerik.Reporting.Report();

                MiscellaneousRpt msRpt = new MiscellaneousRpt();

                msRpt.Report.Name = "MiscellaneousReport";

                msRpt.Report.DataSource = lstData;

               // vm.ReportSource = new InstanceReportSource {  ReportDocument = msRpt.Report };                

               // rpt.DataSource = viewModel.LstReportData;
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message, ex);
            }

            return View(vm);
        }

 

Report Viewer .csHtml: -

 

@model OnlineAppln.Web.UI.ViewModels.MiscellaneousViewModel

@*@model IEnumerable<OnlineAppln.Web.UI.ViewModels.MiscellaneousViewModel>*@

@{
    ViewBag.Title = "MiscellaneousReportViewer";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}


@using (Html.BeginForm("MiscellaneousReportViewer", "ARCReports"))
{
    <div class="cphdiv">
        <div style="width:100%;float:left;height:auto;">
            <div class="span-11">
                <div class="span-11 last">
                    <div class="span-3 last lblcss">
                        <label id="lblmisccode">Misc Type:</label>
                    </div>
                    <div class="span-4 last">
                        @(Html.Kendo().ComboBoxFor(d => d.Type)
                  .Name("Type")
          .Placeholder("Please Select")
                  .DataTextField("Text")
                  .DataValueField("Value")
                  .DataSource(source => source.Read(read => read.Action("GetMistypes", "Miscellaneous")))
          .Suggest(true)
          .HtmlAttributes(new { style = "width:150px;" })
                        )
                    </div>
                </div>

                <div class="span-11 last">
                    <div class="span-3 last" style="padding-top:10px;">
                        <label id="lblmisccode">Misc Code:</label>
                    </div>
                    <div class="span-4 last lblcss">
                        @(Html.Kendo().ComboBoxFor(d => d.Code)
                  .Name("Code")
          .Placeholder("Please Select")
                          .DataTextField("Code")
                                  .DataValueField("MiscId")
                                  .DataSource(source => source.Read(read => read.Action("MiscCodeGet", "Miscellaneous")))
          .Suggest(true)
.HtmlAttributes(new { style = "width:150px;" })
                        )
                    </div>
                </div>
            </div>
            <div class="span-11 last">
                <div class="span-11 last">
                    <div class="span-3half last lblcss">
                        <label id="lblIsactive"> Is Active:</label>
                    </div>
                    <div class="span-4 last">
                        @(Html.Kendo().CheckBoxFor(x => x.IsActive)
                            .HtmlAttributes(new { Id = "CbIsActive" })
                            .Checked(true)
                        )
                    </div>
                </div>
                <div class="span-11 last lblcss">
                    <div class="span-2">
                        <button type="submit" id="btnsubmit" class="btn btn-primary">Search</button>
                    </div>
                    <div class="span-2 last">
                        <button type="button" id="btnclear" class="btn btn-primary">Clear</button>
                    </div>
                </div>
            </div>
        </div>


        <div class="reportViewerdiv">

            @(Html.TelerikReporting().ReportViewer()

                    // Each report viewer must have an id - it will be used by the initialization script
        // to find the element and initialize the report viewer.
        .Id("MiscellaneousReport")
        // The URL of the service which will serve reports.
        // The URL corresponds to the name of the controller class (ReportsController).
        // For more information on how to configure the service please check http://www.telerik.com/help/reporting/telerik-reporting-rest-conception.html.
        .ServiceUrl(Url.Content("~/api/reports/"))
        // The URL for custom report viewer template. The template can be edited -
        // new functionalities can be added and unneeded ones can be removed.
        // For more information please check http://www.telerik.com/help/reporting/html5-report-viewer-templates.html.
        // .TemplateUrl(Url.Content("/ReportViewer/templates/telerikReportViewerTemplate-10.0.16.204.html"))
        // Strongly typed ReportSource - TypeReportSource or UriReportSource.
        .ReportSource(new TypeReportSource() { TypeName = "OnlineAppln.Reports.Masters.MiscellaneousRpt, OnlineAppln.Reports" })


                    // Specifies whether the viewer is in interactive or print preview mode.
        // PrintPreview - Displays the paginated report as if it is printed on paper. Interactivity is not enabled.
        // Interactive - Displays the report in its original width and height with no paging. Additionally interactivity is enabled.
        .ViewMode(ViewMode.Interactive)
        // Sets the scale mode of the viewer.
        // Three modes exist currently:
        // FitPage - The whole report will fit on the page (will zoom in or out), regardless of its width and height.
        // FitPageWidth - The report will be zoomed in or out so that the width of the screen and the width of the report match.
        // Specific - Uses the scale to zoom in and out the report.
        .ScaleMode(ScaleMode.Specific)
        // Zoom in and out the report using the scale
        // 1.0 is equal to 100%, i.e. the original size of the report
        .Scale(1.0)
        // Sets whether the viewer’s client session to be persisted between the page’s refreshes(ex. postback).
        // The session is stored in the browser’s sessionStorage and is available for the duration of the page session.
        .PersistSession(false)
        // Sets the print mode of the viewer.
        .PrintMode(PrintMode.AutoSelect)

            )
        </div>
    </div>
}

<script type="text/javascript">
    $(document).ready(function () {

        $('#MasterLi').addClass("active");
        $('#GeneralUL').css('display', 'block');
        $('#miscLi').css('font-weight', 'bold');

        $('#btnsubmit').click(function () {
            var type = $('#Type').val();
            location.href = "@Url.Action("MiscellaneousReportViewer", "ARCReports")?type=" + type;
        });
    });

</script>

View Model:-

 

 public static List<MiscellaneousViewModel> SeachMisc(string type)
        {
            ARCDbContext dbContext = new ARCDbContext();

            List<MiscellaneousViewModel> lstMVm = new List<MiscellaneousViewModel>();
            try
            {
                List<Miscellaneou> LstMisc = new List<Miscellaneou>();               

                if (!string.IsNullOrEmpty(type))
                    LstMisc = dbContext.Miscellaneous.Where(x => x.Type == type).ToList();
                else
                    LstMisc = dbContext.Miscellaneous.ToList();

                foreach (Miscellaneou misce in LstMisc)
                {
                    MiscellaneousViewModel MvM = (MiscellaneousViewModel)ModelConverter.Convert(misce, typeof(MiscellaneousViewModel));

                    lstMVm.Add(MvM);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return lstMVm;
        }

 

 

 

 

Please, let me know if the approach i'm trying is correct (or) not.

0
Stef
Telerik team
answered on 05 May 2016, 01:23 PM
Hi Obulesh,

Based on the provided information, you are trying to assign report's data in a custom controller's action, which will not work with the HTML5 Viewer.

The HTML5 Viewer is a client-side widget that sends only short string messages to the server - the viewer works in a client-server, not MVC model. Whole instances (reports or data objects) cannot be sent - technology limitation. For more details, check How it works section.

Thus the solution will be to:
  1. Create the model instance in your custom controller's action;
  2. Update the model instance through the custom UI in your View;
  3. Submit the updated data back to the server and save it e.g. in a database;
  4. Request a report by its assembly qualified name or a path to a TRDX file. On processing the report, it will pull its data from the server.


In case you have custom UI that uses the same data as the report, you can filter the report with the same condition as the custom Ui's data. For the purpose configure the report's DataSouce to use a parameterized method, which arguments are mapped to report parameters. Thus you can control the data in the report by updating report parameters only - . In this scenario data is again pulled from the storage on the server (database or other).
For more details on this scenario, please check How To: Pass Values to Report Parameters.

Regards,
Stef
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Obulesh
Top achievements
Rank 1
Answers by
Stef
Telerik team
Obulesh
Top achievements
Rank 1
Share this question
or