ActiveReports 18 .NET Edition
Developers / Create Designer and Viewer Applications / Blazor Viewer Application / Blazor Viewer API
In This Topic
    Blazor Viewer API
    In This Topic

    The page describes the Blazor Viewer API that can be used for initialization or at run time while working with the viewer.

    RenderMode

    Description: The initial render mode - 'Paginated' or 'Galley'. The default value is 'Paginated'.

    Type: Enum: RenderMode

    Accepted values: 'RenderMode.Paginated', 'RenderMode.Galley'

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" RenderMode="RenderMode.Paginated"/>
    

    DefaultExportSettings

    Description: The object containing custom default export settings. Use to preset the export settings' default value and its visibility in the export panel.

    Type: Dictionary<string, Dictionary<string, ExportSetting>>

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" DefaultExportSettings="@defaultExportSettings"/>
    @code{ 
      Dictionary<string, Dictionary<string, ExportSetting>> defaultExportSettings = new Dictionary<string, Dictionary<string, ExportSetting>>()
        {
              {
                  "xls", new Dictionary<string, ExportSetting>(){
                      {
                          "FileName",  new ExportSetting() {Value = "ar", Visible = true}
                      },
                      {
                          "EnableToggles",  new ExportSetting() {Value = false}
                      }
                  }
              }
        };
    }
    

    AutoBackgroundColor

    Description: When set to 'true', the background color of the viewing area is filled with the report's body color. This property is available only for RDLX Dashboard reports.

    Type: bool

    Accepted values: 'true', 'false'

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" AutoBackgroundColor="true" />
    

    AvailableExports

    Description: The array of export types available via export functionality of the viewer.

    Type: ExportTypes[]

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" AvailableExports="availableExportArr"/>
    @code{
        ExportTypes[] availableExportArr = new ExportTypes[] {
                ExportTypes.Pdf, ExportTypes.Xlsx, ExportTypes.Xls, ExportTypes.Json
            };
    }
    

    Locale

    Description: The locale used for displaying the viewer.

    Type: String

    Accepted values: 'en-US' (for English), 'ja-JP' (for Japanese), and 'zh-CN' (for Chinese)

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" Locale="ja-JP"/>
    

    LocaleData

    Description: The JSON containing the localization strings.

    Type: String

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" LocaleData="@_localeData" >
    @code{
        string _localeData = "{\"viewer\": {\"toolbar\": {\"refresh\": \"更新\"} } }";
    }
    

    LocaleUri

    Description: The url of the file containing the localization strings.

    Type: String

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" LocaleUri="localization.json"/>
    

    PanelsLocation

    Description: The location of the panels or panes (search pane, parameters pane, etc.) to the left side ('toolbar') or the right side ('sidebar') of the viewer. The default value is 'toolbar'.

    Type: Enum: PanelsLocation

    Accepted values: 'PanelsLocation.sidebar', 'PanelsLocation.toolbar'

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" PanelsLocation="PanelsLocation.toolbar" />
    

    DisplayMode

    Description: Set the single page or continuous page mode for the viewer.

    Type: Enum: ViewMode

    Accepted values: 'ViewMode.Single', 'ViewMode.Continous'

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" DisplayMode="ViewMode.Single" />
    

    Action

    Description: The callback that is invoked before the viewer opens the hyperlink, bookmark link, drill-down report, or toggles the report control visibility.

    Type: Method (string, object[])

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" Action="actionMethod" />
    @code{
        public void actionMethod(string actionType , object[] actionParams)
        {
            System.Diagnostics.Debug.WriteLine(actionType);
            foreach(var obj in actionParams)
            {
                System.Diagnostics.Debug.WriteLine(obj);
            }
                    }
    }
    

    Error

    Description: The callback that is invoked when an error occurs in the process of displaying the report.

    Type:  Method(ErrorInfo obj)

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" Error="errorMethod" />
    @code{
        public void errorMethod(ErrorInfo obj)
        {
            System.Diagnostics.Debug.WriteLine("Error Message :" + obj.Message);
                       }
    }
    

    HideErrors

    Description: Specify whether to show errors in the viewer ('false' by default).

    Type: bool

    Accepted values: 'true', 'false'

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" HideErrors="true" />
    

    InitialZoomMode

    Description: Set the zoom mode at which the report should open in the viewer.

    Type: String

    Accepted values: 'FitToPage', 'FitToWidth'

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" InitialZoomMode="@ZoomMode.FitToWidth"/>
    

    InitialZoomPercentage

    Description: Set the zoom level in percentage at which the report should open in the viewer. If you set this property to, for example, 100, then the InitialZoomMode is ignored.

    Type: Integer 

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" InitialZoomPercentage="50"/>
    

    The percentage value can range from 25 to 300.

    DocumentLoaded

    Description: The callback that is invoked when a document is loaded entirely on the server.

    Type: Method()

    Returns: Void

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" DocumentLoaded="DocumentLoaded"/>
    @code{
        public void DocumentLoaded()
        {
            System.Diagnostics.Debug.WriteLine("Document Loaded");
        }
    }
    

    ReportService

    Description: Set up the settings to connect the Web API.

    Type: ReportServiceSettings object

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" ReportService="setting" />
    @{
        ReportServiceSettings setting = new ReportServiceSettings()
        {
            Url = "http:example.com/api/reporting",
            SecurityToken = "security_Token",
            OnRequest = (OnRequestInfo obj) =>
            {
                obj.Headers.Add("Authorization", "security_Token");
            }
        };
    }
    

    ViewerInitialized

    Description: The callback that is invoked when the viewer is initialized

    Type:  Method()

    Returns: Void

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" ViewerInitialized="InitializedViewer"/>
    @code{
        private void InitializedViewer()
        {
            System.Diagnostics.Debug.WriteLine("Viewer is initailized now");
                     }
    }
    

    ReportLoaded

    Description: The callback that is invoked when the viewer obtains the information about the requested report.

    Type: Method(ReportInfo obj)

    Returns: Void

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" ReportLoaded="ReportLoaded"/>
    @code{
        public void ReportLoaded(ReportInfo obj)
        {
            System.Diagnostics.Debug.WriteLine("The report " + obj.Name + " was successfully loaded!");
                       }
    }
    

    ParametersPanelSettings

    Description: Set up the parameters panel or pane settings.

    Type: ParametersPanelSettings object
    Enums:

    • ParameterPanelLocation: Adjusts the position of the parameters pane.
      Accepted Value: 'Default', 'Top'
    • ParameterPanelOpen: Sets the parameters pane to be available by default, irrespective of whether a parameter is set to a default value or requires user input.
    • Accepted Value: 'Auto', 'Always'
    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" ParametersPanelSettings="parametersPanelSetting"/>
    @code{
        ParametersPanelSettings parametersPanelSetting = new ParametersPanelSettings()
        {
            Location = ParameterPanelLocation.Default,
            Open = ParameterPanelOpen.Always
                   };
    }
    

    Sidebar

    Description: The viewer's sidebar instance. Use it to toggle the sidebar visibility.

    Returns: Sidebar object

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" ViewerInitialized="InitializedViewer"/>
    @{
    private ReportViewer _viewer;
      
       private void InitializedViewer()   
       {
    Sidebar obj = _viewer.Sidebar;
       }
    }
    

    Parameters

    Description: The array of the {name, value} pairs that describe the values of the parameters used to run the report.

    Type: Parameter[]

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" Parameters="parameterArray"/>
    @code{
        Parameter[] parameterArray = new Parameter[]
        {
            new Parameter
            {
                Name = "Category",
                Values = new string[]{"Business" }
            }
                      };
    }
    

    ReportName

    Description: The name of the report to be shown by the viewer.

    Type: String

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" />
    @code{
    private ReportViewer _viewer;
    private string _currentReport = null;
        protected override void OnInitialized()
        {
    reportsList = ReportsService.GetReports().ToList();
    _currentReport = reportsList.FirstOrDefault();     
        }
    }
    

    Width

    Description: The width of the viewer, by default 100%.

    Type: String

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" Width="50%"/>
    

    Height

    Description: The width of the viewer, by default 100%.

    Type: String

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" Height="50%"/>
    

    Toolbar

    Description: The viewer's toolbar instance. Use it to add the custom elements or remove the existing ones.

    Returns: Toolbar object

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" ViewerInitialized="InitializedViewer"/>
    @{
    private ReportViewer _viewer;
      
       private void InitializedViewer()   
       {
    Toolbar obj = _viewer.Toolbar;
       }
    }
    

    Theme

    Description: Sets the theme on the viewer. The theme can be set to a custom theme or a default theme.

    Set Custom Theme

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" Theme="@_theme"/>
    @code{ 
        private readonly UITheme _theme = new UITheme()
        {
            Name = "activeReports",
            Accent = new Color(234, 137, 57, 255),
            AccentText = new Color(232, 123, 33, 255),
            AccentSecondary = new Color(254, 207, 0, 255),
            AccentWarning = new Color(236, 133, 32, 255),
            AccentError = new Color(191, 42, 42, 255),
            ColorContrast = new Color(255, 255, 255, 255),
            ColorContrastText = new Color(255, 255, 255, 255),
            BackgroundBody = new Color(248, 237, 227, 255),
            BackgroundPanels = new Color(253, 247, 241, 255),
            Shadow = "0 0 10px 1px rgba(0, 0, 0, 0.2)",
            ShadowBorder = "0 0 10px 1px rgba(0, 0, 0, 0.1)",
            Overlay = new Color(0, 0, 0, 38),
            TextColor = new Color(51, 51, 51, 255),
            BorderRadius = 4,
            ElemBackground = new Color(191, 127, 74, 13),
            ElemBackgroundHover = new Color(191, 127, 74, 39),
            BtnGroupHeader = new Color(246, 229, 215, 255),
            BtnGroupHeaderHover = new Color(242, 218, 198, 255),
            DropdownBackground = new Color(255, 255, 255, 255),
            DropdownBorder = new Color(230, 207, 190, 191),
            BindingModified = new Color(77, 202, 125, 255),
            BindingBound = new Color(254, 207, 0, 255),
            BackgroundPanelsSection = new Color(255, 222, 191, 64),
            BackgroundPanelsBorder = new Color(230, 207, 190, 191),
        }
    }
    

    Set Default Theme

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" Theme="@ViewerUIThemes.DefaultDark"/>
    

    BackToParrent

    Description: Makes the viewer to display the parent report of the drill-down report.

    Type: Method

    Returns: Void

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport" ViewerInitialized="InitializedViewer"/>
    @code{   
    private ReportViewer _viewer;
        private void InitializedViewer()
        {
    await  _viewer.BackToParrent();
        }
    }
    

    CurrentPage

    Description: The currently displayed page number.

    Type: Method

    Returns: ValueTask<int>

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport"  DocumentLoaded="@DocumentLoaded"/>
    @code{   
    private async void DocumentLoaded()
        {
            var currentPage = await _viewer.CurrentPage();
                         System.Diagnostics.Debug.WriteLine(currentPage);
                     }
    }
    

    Export

    Description: Exports the currently displayed report.      
    Parameters:

    • exportType: Specifies the export format.
    • callback: Function that is invoked once the export result is available (its Url is passed in the callback)
    • saveAsDialog: Indicates whether the save as dialog should be shown immediately once the export result is ready
    • settings: The export settings are available for RenderingExtensions
    • isCancelRequested: The function is periodically called with a check to cancel the export task

    Type: Method(ExportTypes, Action<string> callback = null, bool = false, Dictionary<string, string> settings = null, Func<bool> isCancelRequested = null, )

    Returns: Void

    Sample code
    Copy Code
    <GrapeCity.ActiveReports.Blazor.ReportViewer @ref="_viewer" ReportName="@reportId" DocumentLoaded="
    @DocumentLoaded"/>
    @code {
     private ReportViewer _viewer;
     private string reportId = "User defined report columns.rdlx";
     private async void DocumentLoaded()
        {
     await _viewer.Export(ExportTypes.Pdf,
     (uri) =>
        {
        //uri to export result
        },
     false,
     new Dictionary<string, string>() { { "Title", "Some Title" } },
     () =>
        {
       //hecking export cancellation
       return false;
        }
     );
        }
    }
    

    GetToc

    Description: Obtains the report TOC.

    Type: Method

    Returns: ValueTask<BookmarkInfo>

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport"  DocumentLoaded="@DocumentLoaded"/>
    @code{   
    private async void DocumentLoaded()
        {
            var toc = await _viewer.GetToc();
                     }
    }
    

    GoToPage

    Description: Makes the viewer display the specific page. Page numeration starts with 1.
    Type: int
    Returns: Void

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport"  DocumentLoaded="@DocumentLoaded"/>
    @code{   
    private async void DocumentLoaded()
        {
                          await _viewer.GoToPage(2);
                     }
    }
    

    OpenReport

    Description: Makes the viewer to display the parent report of the drill-down report.
    Type: Method(string, Parameter[] = null)
    Returns: Void

    Sample code
    Copy Code
    _viewer.OpenReport("TestReport.rdlx");
    OR
        Parameter[] parameterArray = new Parameter[]
    {
            new Parameter
            {
                Name = "Category",
                Values = new string[]{"Business" }
            }
    };
    _viewer.OpenReport("TestReport.rdlx", parameterArray);
    

    PageCount

    Description: Gets the page count of the currently displayed report.
    Type: Method
    Returns: ValueTask<int>

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport"  DocumentLoaded="@DocumentLoaded"/>
    @code{   
    private async void DocumentLoaded()
        {
             var countPage = await _viewer.PageCount();
            System.Diagnostics.Debug.WriteLine(countPage);
                     }
    }
    

    Print

    Description: Prints the currently displayed report if any.
    Type: Method()
    Returns: Void

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport"  DocumentLoaded="@DocumentLoaded"/>
    @code{   
    private async void DocumentLoaded()
        {
             await _viewer.Print();
                     }
    }
    

    Refresh

    Description: Refreshes the report preview.
    Type: Method()
    Returns: Void

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport"  DocumentLoaded="@DocumentLoaded"/>
    @code{   
    private async void DocumentLoaded()
        {
             await _viewer.Refresh();
                     }
    }
    

    Search

    Description: Performs the search of a specific term with specific search options (match case, whole word) and invokes the specific callback with the search result passed.
    Parameters:

    • searchTerm: String to find.
    • searchOptions: The object optionally defines the search options.
    • callback: The function to call after performing the search.

    Type: Method(string, SearchOptions = null, Action<List<SearchResult>> = null)

    Returns: Void

    Sample code
    Copy Code
    <ReportViewer @ref="_viewer" ReportName="@_currentReport"  DocumentLoaded="@DocumentLoaded"/>
    @code{   
    private async void DocumentLoaded()
        {
            //Searching ALFKI keyword in the report
            await _viewer.Search("ALFKI", new SearchOptions()
            {
                MatchCase = true,
                WholePhrase = false
            },
            (List<SearchResult> results) =>
            {
                if (results != null && results.Count > 0)
                {
                    foreach (var res in results)
                    {
                        System.Diagnostics.Debug.WriteLine(res.DisplayText);
                    }
                    
                }
            });
        }
    
    See Also