Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Perform sorting based on user input
Perform sorting based on user input [message #503331] Fri, 11 December 2009 17:36 Go to next message
Neil Wang is currently offline Neil WangFriend
Messages: 105
Registered: July 2009
Senior Member
Hi,

I am exploring possibilities to sort based on user input.
For example, when we run a report, the parameter dialog shows up and it has two radio buttons "Ascending" and "Descending". User can pick either button to decide how a field will be sorted.

I know how to define the parameter but do not know how to use it to sort. please advise.
Re: Perform sorting based on user input [message #503348 is a reply to message #503331] Fri, 11 December 2009 21:06 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Neil,

You can always define the sort in the beforeFactory

importPackage(Packages.org.eclipse.birt.report.model.api);
importPackage(Packages.org.eclipse.birt.report.model.api.ele ments);
importPackage(Packages.com.ibm.icu.util);
importPackage(Packages.org.eclipse.birt.data.engine.api);

delm = reportContext.getDesignHandle().findElement("mytable");
sc = StructureFactory.createSortKey();
sc.setKey("row[\"ORDERNUMBER\"]");
sc.setDirection(params["mysortdirection"].value);
ph = delm.getPropertyHandle(TableHandle.SORT_PROP);
ph.addItem(sc);

or modify an existing one like:

delm = reportContext.getDesignHandle().findElement("mytable2");
ph = delm.getPropertyHandle(TableHandle.SORT_PROP);
//get number or iterate
sk = ph.get(0);
sk.setDirection(params["mysortdirection"].value);

the parameter mysortdirection needs to be either desc or asc.

Jason

Neil Wang wrote:
> Hi,
>
> I am exploring possibilities to sort based on user input.
> For example, when we run a report, the parameter dialog shows up and it
> has two radio buttons "Ascending" and "Descending". User can pick either
> button to decide how a field will be sorted.
>
> I know how to define the parameter but do not know how to use it to
> sort. please advise.
Re: Perform sorting based on user input [message #503787 is a reply to message #503348] Tue, 15 December 2009 18:59 Go to previous messageGo to next message
Neil Wang is currently offline Neil WangFriend
Messages: 105
Registered: July 2009
Senior Member
Hi,

Thank you for your reply. This is what I have done:
1. I have this in the beforeFactory script.
importPackage(Packages.org.eclipse.birt.report.model.api);
importPackage(Packages.org.eclipse.birt.report.model.api.ele ments);
importPackage(Packages.com.ibm.icu.util);
importPackage(Packages.org.eclipse.birt.data.engine.api);

delm = reportContext.getDesignHandle().findElement("Package");
sc = StructureFactory.createSortKey();
sc.setKey("row[\"ORDERNUMBER\"]");
sc.setDirection(params["SortDirection"].value);
ph = delm.getPropertyHandle(TableHandle.SORT_PROP);
ph.addItem(sc);

and this is what I got:
The following items have errors:

Table Package:
- Fail to compute value from sort, group or filter expression.
A BIRT exception occurred: There are errors evaluating script "row[ORDERNUMBER"]"; Invalid bound column name: ORDERNUMBER
Caused by: org.mozilla.javascript.EvaluatorException: Invalid bound column name: ORDERNUMBER.

please advise.
Re: Perform sorting based on user input [message #503802 is a reply to message #503787] Tue, 15 December 2009 20:50 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Neil,

Select the table in the design you are trying to change sorting on.
Next select the binding tab next to properties. This list all of the
columns you can sort on. Is ORDERNUMBER in this list?

Jason

Neil Wang wrote:
> Hi,
>
> Thank you for your reply. This is what I have done:
> 1. I have this in the beforeFactory script.
> importPackage(Packages.org.eclipse.birt.report.model.api);
> importPackage(Packages.org.eclipse.birt.report.model.api.ele ments);
> importPackage(Packages.com.ibm.icu.util);
> importPackage(Packages.org.eclipse.birt.data.engine.api);
>
> delm = reportContext.getDesignHandle().findElement("Package");
> sc = StructureFactory.createSortKey();
> sc.setKey("row[\"ORDERNUMBER\"]");
> sc.setDirection(params["SortDirection"].value);
> ph = delm.getPropertyHandle(TableHandle.SORT_PROP);
> ph.addItem(sc);
>
> and this is what I got:
> The following items have errors:
>
> Table Package:
> - Fail to compute value from sort, group or filter expression.
> A BIRT exception occurred: There are errors evaluating script
> "row[ORDERNUMBER"]"; Invalid bound column name: ORDERNUMBER
> Caused by: org.mozilla.javascript.EvaluatorException: Invalid bound
> column name: ORDERNUMBER.
>
> please advise.
Re: Perform sorting based on user input [message #503847 is a reply to message #503802] Tue, 15 December 2009 19:42 Go to previous messageGo to next message
Neil Wang is currently offline Neil WangFriend
Messages: 105
Registered: July 2009
Senior Member
Hi Jason,

I don't have "ORDERNUMBER" in any of the data set. One of the data sets is called "Package" and there is a table called "Package" in the layout. My goal is to be able to sort the entries in the detail row of the "Package" table. I can definitely add a field called "ORDERNUMBER" under the "Package" data set and establish a binding between "ORDERNUMBER" and the "Package" table in the layout. Should I do this? If yes, what value should it have?
Also, I am using BIRT 2.3.2.

please advise.
Re: Perform sorting based on user input [message #503857 is a reply to message #503847] Wed, 16 December 2009 00:18 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Neil,

Swap
sc.setKey("row[\"ORDERNUMBER\"]");

with whatever column you want to sort on
sc.setKey("row[\"MYCOL\"]");

Jason

Neil Wang wrote:
> Hi Jason,
>
> I don't have "ORDERNUMBER" in any of the data set. One of the data sets
> is called "Package" and there is a table called "Package" in the layout.
> My goal is to be able to sort the entries in the detail row of the
> "Package" table. I can definitely add a field called "ORDERNUMBER" under
> the "Package" data set and establish a binding between "ORDERNUMBER" and
> the "Package" table in the layout. Should I do this? If yes, what value
> should it have?
> Also, I am using BIRT 2.3.2.
>
> please advise.
Re: Perform sorting based on user input [message #503994 is a reply to message #503857] Wed, 16 December 2009 18:34 Go to previous message
Neil Wang is currently offline Neil WangFriend
Messages: 105
Registered: July 2009
Senior Member
It works. Thank you very much.
Previous Topic:BIRT Master page
Next Topic:Rounding behaviour BIRT and Excel
Goto Forum:
  


Current Time: Tue Apr 16 10:36:28 GMT 2024

Powered by FUDForum. Page generated in 0.08105 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top