Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could you pls provide a example of how to user the dataset attribute in report JSON. #52

Open
joseespinozac opened this issue Aug 19, 2020 · 2 comments

Comments

@joseespinozac
Copy link

joseespinozac commented Aug 19, 2020

I would love a more detailed example on how to use or declare the dataset in the report JSON

let report = {
        report: 'usersreport',
        data: {
            name: 'Joe'
        },
        dataset: jasper.toJsonDataSource({  how to send this, and how I need to build my jrxml to use the dataser I declare here
            name: 'Joe',
            hola: 'mundo'
        },'data')
    };

Sorry for my english
And please tell me if I can send arrays? and how to do it

@dcsline
Copy link

dcsline commented Jun 19, 2021

look in my tested content for sample js:
var fs = require('fs');

var jasper = require('node-jasper')({
path: '../lib/jasperreports-5.6.0',
reports: {
stock_ofertas: {
jasper: __dirname + '/sample.jasper',
jrxml: __dirname + '/sample.jrxml',
conn: 'in_memory_json'
}
}
});

jasper.ready(function() {
var r = jasper.export(
{
report: 'stock_ofertas',
data: {
language: 'spanish',
// on jasper make a parameter named "dataset2" and use on a subreport:
// ((net.sf.jasperreports.engine.data.JsonDataSource)$P{dataset2})
dataset2: jasper.toJsonDataSource(
{
dados: [{ value: 1, value: 2 }]
},
'dados'
)
},
dataset: [
{
name: 'Gonzalo',
lastname: 'Vinas' // TODO: check on UTF-8
},
{
name: 'Agustin',
lastname: 'Moyano'
}
]
},
'pdf'
);

//fs.writeFile(__dirname + '/sample.pdf', r);
fs.writeFile(__dirname+ '/sample.pdf', r, (error)=>{
    if(error) console.log(error);
})

});

@dcsline
Copy link

dcsline commented Jun 19, 2021

Why you want build an json from an array? If you want do this, then look for tools which are build the json from an array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants