Generate reports in birt using user input. When input is null, everything should be fetched otherwise corresponding data should be shown

那年仲夏 提交于 2019-12-12 05:43:58

问题


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!


回答1:


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.




回答2:


Create your paremater using a like statement

 where students_roll_no like ?

Create your report paramater using as a text box, with a defualt value of %

Because the percent '%' is the SQL wildcard, it returns all values. If the user enters a Student Roll number, it returns only that record. Additionally the user can enter 0500% and get all the records that begin 0500.



来源:https://stackoverflow.com/questions/6453299/generate-reports-in-birt-using-user-input-when-input-is-null-everything-should

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!