How to add javascript library into jsReport



  • I want to try using a javascript library in jsReport.
    When I add the library to the <head> section of report and the library is an external library, it works fine:

    <script src="https://website.com/libraries/jsLibrary.min.js"></script> 
    

    But if I have the source of the library that I want to include directly in report, that is not working. I have tried adding javascript library inside the report folder and accessing it the following way but it does not work:

    <script type="text/javascript" src="/jsLibrary.min.js"></script>
    

    I have also tried adding the javascript file as an asset of the report and then using following code and it does not work:

    <script type="text/javascript" src=" {#asset jsLibrary.min.js}"></script>
    

    Any help will be appreciated.

    Thanks.



  • <script type="text/javascript" src="/jsLibrary.min.js"></script>

    You would need to use path with file:///

    <script type="text/javascript" src=" {#asset jsLibrary.min.js}"></script>

    This would be like this

    <script type="text/javascript">
    {{asset jsLibrary.min.js}}
    or 
    {#asset jsLibrary.min.js}
    </script>
    

    If the library is an npm module, you can use it also like this
    https://jsreport.net/learn/templating-engines#module-modulename-

    <script>{{module "moment"}}</script>
    <script>console.log(moment())</script>
    


  • Thanks a lot for the reply.
    I got it to work with the following option:

    <script type="text/javascript">
    {#asset jsLibrary.min.js}
    </script>
    

Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.