Blazor - add custom Viewer button

Stimulsoft Reports.NET discussion
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: Blazor - add custom Viewer button

Post by Lech Kulikowski »

Hello

Please let us know if you need any additional help.
mrapi
Posts: 277
Joined: Sat Dec 20, 2008 1:08 am

Re: Blazor - add custom Viewer button

Post by mrapi »

Hi
after update from 2022.4.5 to 2023.1.1 above code is not working,got in console:

Code: Select all

Unhandled Exception:
 Microsoft.JSInterop.JSException: this.WebViewer1.SmallButton is not a function
 blazor.webassembly.js:1 TypeError: this.WebViewer1.SmallButton is not a function
works fine if I revert to 2022.4.5
thanks
Max Shamanov
Posts: 786
Joined: Tue Sep 07, 2021 10:11 am

Re: Blazor - add custom Viewer button

Post by Max Shamanov »

Hello,

We need some additional time to investigate the issue, we will let you know about the result.

Thank you.
Max Shamanov
Posts: 786
Joined: Tue Sep 07, 2021 10:11 am

Re: Blazor - add custom Viewer button

Post by Max Shamanov »

Hello,

Form version 2023.1.1 we made some changes in Stimulsoft Blazor.
Now you need to use the following code in _Host.cshtml:

Code: Select all

 <script>
        var createButton = function () {
            // 'jsWebViewer1' is a 'js' prefix plus the component ID
            var customButton = this.jsWebViewer1.SmallButton("customButton", "Custom Button", "emptyImage");
            customButton.image.src = "icon.png";
            customButton.action = function () {
                alert("Custom Button Event");
            }
            var toolbarTable = this.jsWebViewer1.controls.toolbar.firstChild.firstChild;
            var buttonsTable = toolbarTable.rows[0].firstChild.firstChild;
            var customButtonCell = buttonsTable.rows[0].insertCell(0);
            customButtonCell.appendChild(customButton);
        }
    </script>
and this code at Viewer.razor:

Code: Select all

<StiBlazorViewer ID="WebViewer1" Report="@report" OnViewerAfterRender="@OnAfterRenderViewer" />

@code
{
    //Report object to use in viewer
    private StiReport report;

    protected override void OnInitialized()
    {
        base.OnInitialized();
        //Init base font
        StiFontCollection.AddFontFile($"Fonts/OpenSans-Regular.ttf");
        //Create empty report object
        report = new StiReport();
        //Load report template
        report.Load($"Reports/TwoSimpleLists.mrt");
    }

    private void OnAfterRenderViewer()
    {
        JSRuntime.InvokeVoidAsync("createButton");
    }

}
https://github.com/stimulsoft/Samples-B ... %20Toolbar

Thank you.
mrapi
Posts: 277
Joined: Sat Dec 20, 2008 1:08 am

Re: Blazor - add custom Viewer button

Post by mrapi »

it is working.thanks!
Max Shamanov
Posts: 786
Joined: Tue Sep 07, 2021 10:11 am

Re: Blazor - add custom Viewer button

Post by Max Shamanov »

Hello,

You are Welcome!
Post Reply