使用用户输入以Birt格式生成报告.当输入为空时,应提取所有内容,否则应显示相应的数据 [英] Generate reports in birt using user input. When input is null, everything should be fetched otherwise corresponding data should be shown
问题描述
我必须使用用户输入参数创建一个Birt报告.就像当仪表留空,应从表中获取所有值,否则当用户输入学生卷号时,应获取相应的数据.可以通过Birt报告完成此操作吗?如果是,那么请提出一种方法.
谢谢!
是的,您可以这样做.如果参数是可选的,则不能使用数据集参数(查询中带有?),因为它将为null.相反,您必须使用JavaScript修改查询.
像往常一样创建一个报告参数,在本例中为'stud_no'.然后在您的SQL中添加一个您可以肯定确定是唯一的注释,无论您想在何处插入子句,我都使用-$ stud_no $之类的东西.
然后在beforeOpen中将这样的脚本添加到您的数据集中:
if(params ["stud_no"].value){this.queryText = this.queryText.replace(-$ stud_no $","and stud_no =" + params ["stud_no"]));}
当参数具有值时,它将用子句替换注释.您可以在搜索字符串中使用正则表达式,然后根据需要将其插入多个位置.
I have to create a birt report with user input parameters. It is something like when the para
meter is left blank it should fetch all values from a table otherwise when the user inputs the students roll no.,the corresponding data should be fetched. Can this be done through Birt report? If yes, then please suggest a way.
Thanks!
Yes, you can do that. If the parameter is optional you can't use the Dataset Parameter (with a ? in your query), because it will be null. Instead you have to modify your query using JavaScript.
Create a Report Parameter like usual, in this case 'stud_no'. Then add a comment in your SQL that you are reasonably sure is unique, I use something like --$stud_no$, wherever you want your clause inserted.
Then add a script like this to your Data Set, in beforeOpen:
if (params["stud_no"].value){
this.queryText = this.queryText.replace("--$stud_no$", "and stud_no = " + params["stud_no"]);
}
This replaces the comment with the clause when the parameter has a value. You can use regex in the search string, and then you can also insert it multiple places if you want.
这篇关于使用用户输入以Birt格式生成报告.当输入为空时,应提取所有内容,否则应显示相应的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!