Nightmarish Pawnshop Mystic

    nativescript-telerik-reporting
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.3 • Public • Published

    Build Status npm downloads npm downloads npm

    A NativeScript plugin for easy access to Telerik Rporting REST API.

    Installation

    Run the following command from the root of your project:

    tns plugin add nativescript-telerik-reporting

    This command automatically installs the necessary files, as well as stores nativescript-telerik-reporting as a dependency in your project's package.json file.

    Configuration

    There is no additional configuration needed!

    API

    ReportingClient

    Methods

    • constructor(ReportingClientOptions)
      Creates a reporting client instance with the given serverUrl. Note this should be the root of your site where you host the REST service and should not include /api/reports in it.
      Also you can send additionalHeaders which will be sent with every request. Useful for sending authentication in case your reporting service requires authentication.
    • getAvailableDocumentFormats(): Promise<DocumentFormat[]>
      Gets an array of supported document export formats by the server. This method can be called without registering the client. (API Reference)
    • register(): Promise
      Registers the client with the server. (API Reference)
    • unregister(): Promise
      Unregisters the client from the servers. You need to call this once you finished using the reporting client so it can free up resources on the server. (API Reference)
    • getReportParameters(ReportSource): Promise<ReportParameter[]>
      Gets info about the parameters for the given reports. Also can be used to check the validity of the given parameters for the given report. (API Reference)
    • createInstance(ReportSource): Promise
      Creates a ReportingInstance that can be used to render and download reports from the server. (API Reference)

    ReportingInstance

    Methods

    • createDocument(DocumentFormatKey): Promise
      Creates a ReportingDocument with the given export format. (API Reference)
    • destroy(): Promise
      Destroys the reporting instance from the server. It is important to call this method once you finish your work so it can free the resources on the server. (API Reference)

    ReportingDocument

    Methods

    • getInfo(): Promise
      Gets info about the rendered report document, for example if it is ready on the server, how many pages it has, etc.(API Reference
    • download(File?): Promise
      Downloads the prepared document from the server. By default it names the file with documentId adds an appropriate extension and saves the file in the device specific temp folder. In case you need to save the file somewhere else, or need to name it differently you can send a File instance to this method.
    • getPage(number): Promise
      Gets information about the given page. (API Reference)
    • destroy(): Promise
      Destroys the reporting document from the server. It is important to call this method once you finish your work so it can free the resources on the server. (API Reference)

    Usage

    A typical usage scenario is when you want to generate a report on your server and the download the file in an appropriate format (for example a PDF document). Below is an example how you can make this. You start by creating a client with your server's URL. Then you register your client, create an instance and a document. Finally you download the document to the mobile device.

    const req: ReportSource = {
        report: "Telerik.Reporting.Examples.CSharp.Invoice, CSharp.ReportLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
        parameterValues: {
            OrderNumber: "SO51081",
            ForYear: 2003,
            ForMonth: 7,
        },
    };
    const reportingClient = new ReportingClient({ serverUrl: "https://....." });
    reportingClient.register()
        .then(() => reportingClient.createInstance(req))
        .then((instance) => {
            instance.createDocument({ format: documentFormat } as any).then((document) => {
                document.download().then((file) => {
                    utils.ios.openFile(file.path);
                    viewModel.set("isBusyIn", false);
     
                    document.destroy()
                        .then(() => instance.destroy())
                        .then(() => reportingClient.unregister);
                });
            });
        });

    It is really important to remember to call destroy() for your instances and documents and to unregister() your client as this frees up resources on the server. Also it is a good idea to reuse clients/instances whenever possible.

    Demos

    This repository plain NativeScript demo. In order to run those execute the following in your shell:

    $ git clone https://github.com/peterstaev/nativescript-telerik-reporting
    cd nativescript-telerik-reporting
    $ npm install
    $ npm run demo-ios

    This will run the plain NativeScript demo project on iOS. If you want to run it on Android simply use the -android instead of the -ios sufix.

    Donate

    Donate

    bitcoin:14fjysmpwLvSsAskvLASw6ek5XfhTzskHC

    Donate

    Install

    npm i nativescript-telerik-reporting

    DownloadsWeekly Downloads

    10

    Version

    1.0.3

    License

    Apache-2.0

    Unpacked Size

    24.6 kB

    Total Files

    14

    Last publish

    Collaborators

    • pstaev