npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jsreport/jsreport-browser-client

v4.1.0

Published

jsreport browser client

Downloads

8,544

Readme

@jsreport/jsreport-browser-client

NPM Version

Adds recipe html-with-browser-client which creates html output with attached jsreport browser client script.

The html output is then extended with jsreport global object. That can be used to invoke jsreport server rendering directly from the output report.

See the browser-client for API documentation.

Export part of the report to PDF

The most simple scenario. You have html report but you want to additionally add controls for printing particular parts into PDF.

<div id='printedArea'>
    <h1>Hello world</h1>
</div>
<input type='button' onclick='print()' value='print me'></input>
<script>
    function print() {
        jsreport.download('report.pdf', {
          template: {
              content: document.getElementById('printedArea').innerHTML,
              engine: 'none',
              recipe: 'phantom-pdf'
        }});
    }
</script>

Drill down to sub report

Also very common scenario. The report is too complex to display at once and you want let the users to drill down to particular sections.

The master template can contain several links to the detail drill down. Every link can then render different template and also push additional information through data property.

Hello from master....
<input type='button' onclick='detail()' value='Drill down'></input>

<script>
    function detail() {
        jsreport.render('_self', {name: 'detail', data: { detailId: 'foo' }});
    }
</script>

The detail template can use data provided from the master template or use custom script to actively fetch required data. There can be also back button for navigating back to the master template.

Hello from detail {{detailId}} ....
<input type='button' onclick='window.history.back()' value='back'/>

<script>
    function detail() {
        jsreport.render('_self', { template: { name: 'master'} })
    }
</script>

The whole usecase can be implemented also through AJAX calls, this can prevent URL changes.

jsreport.renderAsync({ template: { name: 'master'} }).then(function(r) {
	document.open();
    document.write(r.toString());
    document.close();
});

Editable templates

The last example shows how to use the jsreport borwser client to edit and preview the template in third party WYSIWYG editor.

<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>

<div>
    <input type='button' value='Edit Template' id='editACE' onclick='edit()'/>
    <input type='button' value='Save' id='refresh' onclick='refresh()'/>
</div>

<div id='editorBox'>
</div>

<div id="reportBox" >
</div>

<script>
    var template;
    var templateName = 'My editable report template';
    var data = { foo: '...' };

    //load template definition so we can edit it's content
    jsreport.getTemplateByName(templateName).then(function(r) {
       template = r;
    });

    //also render into the preview pane
    jsreport.render('reportBox', {
      template: { name: templateName },
      data: data
    });

    //open editor with the edited template content
    function edit() {
        tinymce.init({ selector:'#editorBox' });
        tinyMCE.activeEditor.setContent(template.content);
    }

    //save the template with updated content and preview
    function refresh() {
        template.content = tinyMCE.activeEditor.getContent()
        tinyMCE.activeEditor.destroy();
        document.getElementById('editorBox').innerHTML = '';
        jsreport.updateTemplate(template).then(function() {
            jsreport.render('reportBox', {
	            template: { name: templateName },
	            data: data
	        });
        });
    }

</script>

Changelog

4.1.0

  • internal changes to support new response.output api

4.0.0

  • minimum node.js version is now 18.15.0
  • update studio build against new webpack and babel

3.1.2

  • fix url normalization. it was breaking playground serverUrl

3.1.1

  • changes to enable caching of system helpers

License

MIT