Possible to automatically add/remove table rows based data?



  • Quick background: I have a data collection app where the user fills out information, and within jsreport I need to create a table using information that the user collects (I'm bringing the data from my app into jsreport in JSON format). For the sake of keeping things simple, say I have 10 fields within my app that I want to use to populate a table in a report template. However, not all 10 fields will contain data and I only want to populate the table with a field ONLY if it contains data (this will prevent the table from being mostly blank rows in the event there's only 1 piece of information that will need to populate it). If there's only 1 field that contains data out of that 10, then I want the table to have 1 row. If there's 2 pieces of data, then I want the table to have 2 rows... etc.

    Is it possible in jsreport to programatically create a table of "x" rows based on the data that is brought in? And how would that HTML look in the actual report template itself?

    I can't seem to find the answer to this anywhere, but if it exists I would be greatly appreciative if you could point me in the right direction. Thank you in advance for any help!



  • It seems to me this is a common job you do with templating engines.

    In jsreport, templating engines like handlebars are used to dynamically assemble the html.
    These engines are just javascript with some special marks, but it doesn't limit you in any way and you should be able to reach what you describe.

    If you are new here, I recommend check some basic examples
    https://playground.jsreport.net/
    Our docs to handlebars
    https://jsreport.net/learn/handlebars
    And when you need to go deeper, check the handlebars official docs and google out handlebars examples
    https://handlebarsjs.com/


Log in to reply
 

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