Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
sorting on summary field by clicking on the column of cross tab
nppk
I am using a crosstab for displaying the number of products ordered per customers, per product.
My rows are showing the customers, columns the products and as summary i am displaying the quantity.
On clicking the product1(header), I need to sort the table based on the quantity of product1.
For eg :
cust | prd1 | prd2| prd3
cust1 | 2 | 0 | 1
cust2 | 1 | 4 | 3
cust3 | 3 | 2 | 1
cust4 | 1 | 2 | 4
so on clicking prd1 the result should be :
cust | prd1 | prd2| prd3
cust2 1 4 3
cust4 1 2 4
cust1 2 0 1
cust3 3 2 1
clicking again on prd1 should result in :
cust | prd1 | prd2| prd3
cust3 3 2 1
cust1 2 0 1
cust2 1 4 3
cust4 1 2 4
clicking on prd2 should result in
cust | prd1 | prd2| prd3
cust1 2 0 1
cust3 3 2 1
cust4 1 2 4
cust2 1 4 3
Could you please suggest how to implement this.
Please find the attached sample report with the post.
Thanks in advance for the help
Find more posts tagged with
Comments
kclark
nppk, take a look at the report I've attached. You'll need to use hidden parameters and a little bit of scripting to do this. When the link is clicked it opens the report again passing the value of what the crosstab needs to be sorted by. It also checks if the current sort direction is ascending or descending, then passes the opposite to the report parameter using the following<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>if(params["SortDirection"].value=="Ascending") {
"Descending"
} else {
"Ascending"
}</pre>
<br />
The actual sorting is done in the beforeFactory()<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
importPackage(Packages.org.eclipse.birt.report.item.crosstab.core.de);
importPackage( Packages.org.eclipse.birt.report.model.api );
importPackage( Packages.org.eclipse.birt.report.item.crosstab.core.util);
importPackage( Packages.org.eclipse.birt.report.item.crosstab.core);
importPackage( Packages.org.eclipse.birt.report.model.api.elements);
var eF = reportContext.getDesignHandle().getElementFactory();
var srt = eF.newSortElement();
if( params["SortOn"].value == "Amount" ){
srt.setKey("data[\"QUANTITYORDERED_Group/PRODUCTCODE\"]");
}else{
srt.setKey("data[\"PRICEEACH_Group/PRODUCTCODE\"]");
}
if( params["SortDirection"].value == "Ascending" ){
srt.setDirection(DesignChoiceConstants.SORT_DIRECTION_ASC);
}else{
srt.setDirection(DesignChoiceConstants.SORT_DIRECTION_DESC);
}
var xtab = reportContext.getDesignHandle().findElement("mycrosstab");
var xtabhandle = xtab.getReportItem();
var rws = xtabhandle.getCrosstabView(ICrosstabConstants.ROW_AXIS_TYPE);
var lvh = rws.getDimension("Group").getLevel(0);
lvh.getModelHandle( ).add( ILevelViewConstants.SORT_PROP, srt );</pre>
<br />
Let me know if you have any questions
nppk
Hello Clark,
Happy New year
Thanks for the quick response.
But I am afraid to tell you that this was not what I was exactly looking for.
I have a crosstab with customers are rows, products as columns and quantity as summary field.
What I need is when the user is clicking on Product1, the cross table should short the table based on the quatities for product1. Similary on clicking Product2 it should based on quatity for products2.
In my case there is only one measurement ie quantity.
cust | prd1 | prd2| prd3
cust1 | 2 | 0 | 1
cust2 | 1 | 4 | 3
cust3 | 3 | 2 | 1
cust4 | 1 | 2 | 4
so on clicking prd1 the result should be :
cust | prd1 | prd2 | prd3
cust2 | 1 | 4 | 3
cust4 | 1 | 2 | 4
cust1 | 2 | 0 | 1
cust3 | 3 | 2 | 1
In the example you have mentioned is based two different measurements.
Could you please let me know how to achieve this.
Thanks & Regards
Nppk
nppk
Hello Clark,<br />
<br />
I am still looking for the solution for sorting the crosstab based on the summary field.<br />
Could you please suggest a solution.<br />
<br />
What I am looking for is :<br />
I have a crosstab with customers are rows, products as columns and quantity as summary field.<br />
What I need is when the user is clicking on Product1, the cross table should short the table based on the quatities for product1. Similary on clicking Product2 it should based on quatity for products2.<br />
In my case there is only one measurement ie quantity.<br />
<br />
cust | prd1 | prd2| prd3<br />
<br />
cust1 | 2 | 0 | 1<br />
cust2 | 1 | 4 | 3<br />
cust3 | 3 | 2 | 1 <br />
cust4 | 1 | 2 | 4<br />
<br />
so on clicking prd1 the result should be :<br />
<br />
cust | prd1 | prd2 | prd3<br />
<br />
cust2 | 1 | 4 | 3<br />
cust4 | 1 | 2 | 4<br />
cust1 | 2 | 0 | 1<br />
cust3 | 3 | 2 | 1<br />
<br />
In the example you have mentioned is based two different measurements, but in my case there is only one measurement.<br />
<br />
Thanks in advance for the help<br />
<br />
Thanks & Regards,<br />
Nppk<br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="'nppk'" data-cid="113019" data-time="1357576726" data-date="07 January 2013 - 09:38 AM"><p>
Hello Clark,<br />
<br />
Happy New year
<br />
Thanks for the quick response.<br />
But I am afraid to tell you that this was not what I was exactly looking for.<br />
<br />
I have a crosstab with customers are rows, products as columns and quantity as summary field.<br />
What I need is when the user is clicking on Product1, the cross table should short the table based on the quatities for product1. Similary on clicking Product2 it should based on quatity for products2.<br />
In my case there is only one measurement ie quantity.<br />
<br />
cust | prd1 | prd2| prd3<br />
<br />
cust1 | 2 | 0 | 1<br />
cust2 | 1 | 4 | 3<br />
cust3 | 3 | 2 | 1 <br />
cust4 | 1 | 2 | 4<br />
<br />
so on clicking prd1 the result should be :<br />
<br />
cust | prd1 | prd2 | prd3<br />
<br />
cust2 | 1 | 4 | 3<br />
cust4 | 1 | 2 | 4<br />
cust1 | 2 | 0 | 1<br />
cust3 | 3 | 2 | 1<br />
<br />
In the example you have mentioned is based two different measurements.<br />
<br />
Could you please let me know how to achieve this.<br />
Thanks & Regards<br />
Nppk<br /></p></blockquote>
kclark
nppk,<br />
I've attached another example that shows what you're trying to do with the crosstab sorting. The main difference is here.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
var xtab = reportContext.getDesignHandle().findElement("mycrosstab");
var xtabhandle = xtab.getReportItem();
var rws = xtabhandle.getCrosstabView(ICrosstabConstants.ROW_AXIS_TYPE);
var sh = rws.getDimension("Group3").getLevel(0).getModelHandle().getProperty("sort").get(0);
sh.getMember().setValue(params["sortOn"]);</pre>
<br />
I had to use getMember() to tell the crosstab what to sort by. Take a look at the example and let me know if this meets your requirements.
Jenkinsj5
Clark
I tried several times to add the comment below to your deveshare, but it will not post. Did you set something to disallow comments or is it some other problem?
This downloaded as sortcrosstab(1).rptdesign for me, the name had to be changed to sortcrosstab.rptdesign [remove '(1)'] for the report to function. Be sure and read the blog post for how it all works.
kclark
<blockquote class='ipsBlockquote' data-author="'Jenkinsj5'" data-cid="113287" data-time="1358270453" data-date="15 January 2013 - 10:20 AM"><p>
Clark <br />
<br />
I tried several times to add the comment below to your deveshare, but it will not post. Did you set something to disallow comments or is it some other problem?<br />
<br />
This downloaded as sortcrosstab(1).rptdesign for me, the name had to be changed to sortcrosstab.rptdesign [remove '(1)'] for the report to function. Be sure and read the blog post for how it all works.<br /></p></blockquote>
<br />
Thanks for the info, I've changed the filename. I'm not sure why it won't let you comment I'll look at the settings again.
nppk
Hello Clark,
Thanks for the sample. I downloaded the same and on running the report, when I click on the product id, it is opening a new report but its not in sorted order, its exactly same as original. Could you please check the same.
Also could you let know in below :
var sh = rws.getDimension("Group3").getLevel(0).getModelHandle().getProperty("sort").get(0);
what is Group3 representing ?
Eagerly waiting for the reply
Thanks & Regards,
Preeti
nppk
Hello Clark,
Still looking forward for th reply and solution.
Thanks & Regards
Preeti
Hello Clark,
Thanks for the sample. I downloaded the same and on running the report, when I click on the product id, it is opening a new report but its not in sorted order, its exactly same as original. Could you please check the same.
Also could you let know in below :
var sh = rws.getDimension("Group3").getLevel(0).getModelHandle().getProperty("sort").get(0);
what is Group3 representing ?
Eagerly waiting for the reply
Thanks & Regards,
Preeti
Quas
thanks a lot for know how, really helpful