Author Topic: sorting columns by clicking headers  (Read 14882 times)

Offline faris

  • Full Member
  • ***
  • Join Date: Nov 2007
  • Posts: 15
  • Forum Citizenship: +0/-0
sorting columns by clicking headers
« on: 21 Nov 2007 12:34:21 am »
hi,
i want to sort columns in ascending/descendin order by clicking headers.thanks in advance.

Offline HariG

  • Full Member
  • ***
  • Join Date: Nov 2007
  • Posts: 28
  • Forum Citizenship: +2/-2
Re: sorting columns by clicking headers
« Reply #1 on: 21 Nov 2007 06:45:37 am »
You can achieve this by using JSP coding with the help of a HTML object

Offline faris

  • Full Member
  • ***
  • Join Date: Nov 2007
  • Posts: 15
  • Forum Citizenship: +0/-0
Re: sorting columns by clicking headers
« Reply #2 on: 22 Nov 2007 06:17:51 am »
Can u explain it in detail?

Offline HariG

  • Full Member
  • ***
  • Join Date: Nov 2007
  • Posts: 28
  • Forum Citizenship: +2/-2
Re: sorting columns by clicking headers
« Reply #3 on: 26 Nov 2007 04:58:05 am »
Hi Faris,

When you want to sort the columns by clicking the headers you can insert a html object over there and can put some code [JSP] as how you want, please find the attached zip folder which contains XML code with the same scenario, open the same from clip board in Report studio, also note that you can use the same html object [which is there in that report] for your report.


Regards,
Venu.

Offline cognosjon

  • Community Leader
  • *****
  • Join Date: Jul 2006
  • Posts: 192
  • Forum Citizenship: +10/-2
Re: sorting columns by clicking headers
« Reply #4 on: 26 Nov 2007 06:07:47 am »
I downloaded this Cognos Supportlink document some time ago (see attached file) I tried it at the time and it worked ok and all with no Java coding.


hope it helps

Jonathan

Offline HariG

  • Full Member
  • ***
  • Join Date: Nov 2007
  • Posts: 28
  • Forum Citizenship: +2/-2
Re: sorting columns by clicking headers
« Reply #5 on: 26 Nov 2007 11:16:53 pm »
We are unable to download the attached document, pelase find the error message.

Offline cognosjon

  • Community Leader
  • *****
  • Join Date: Jul 2006
  • Posts: 192
  • Forum Citizenship: +10/-2
Re: sorting columns by clicking headers
« Reply #6 on: 27 Nov 2007 03:03:18 pm »
see what you mean about the error code, very odd, I can download it with no probs. Other
than that i'll try and paste document though you will obviously lose all the screenshots.

so here goes......................................(if you let me have your email address I can mail the attachment to you if you wish)

One Click Dynamic Column Sorting in a Report

by Adrian Pocovnicu, ISA Consulting

This technique allows you to dynamically sort a report by column by clicking on the column header plus it also enables you to change the sort order by repeating the click. This technique works with ReportNet as well as Cognos 8.1 and 8.2 reports. No Java Script or SDK is required to achieve this.
           
To create a list report that allows you to dynamically sort the data ascending or descending by pressing each column’s header you will need:
•   A parameter that provides the column used for sorting;
•   A parameter that provides the sort order (ascending/descending);
•   A drill through on each column title that will be sorted and pass the full name of that column. Also a pass sort order to change it each time a drill through occurs.
Steps:
1.   Create a new list report using Go Sales and Retailers package.
2.   From Insertable Objects Pane, expand Products query subject and drag Product line and Product type into the list.
3.   In Query Explorer go to Query1.
4.   Click on Product line data item and press CTRL+C and then CTRL+V to duplicate Product line. Repeat step 4 for Product type.
5.   Double-click on Product line1 (created at step 4) to edit it, and add an apostrophe to the beginning and to the end of the expression so it looks like this:
'[gosales_goretailers].[Products].[Product line]' and press OK.
Repeat step 5 for Product type1.
6.   From the Toolbox drag a Data Item underneath Product type1. In the Expression Editor that pops-up type:
#prompt('p_SortColumn','token','[gosales_goretailers].[Products].[Product line]')#
Click OK. (Column that we will sort on, will be the value of this parameter.)
7.   Rename newly created data item to: Sort_item_asc.
8.   In Page Explorer, click on Page 1 and then click anywhere in the list. From the ReportStudio men, click on Data and then Advanced Sorting...
9.   In the Grouping & Sorting dialog that pops-up drag Sort_item_asc on top of Detail Sort List. Click OK.
 
Figure 1: Grouping and Sorting dialogue
10.   Save the report and call it Cognos Sorting.
11.   Click on the header of the column Product line (the Properties pane should display List Column Title next to Ancestor Selector).
12.   In the Properties pane double click Drill Throughs. Click New Drill Through. For Report choose Cognos Sorting, for action choose Run the report, click to edit parameters, choose Pass data item values as Method and for Value select Product line1, see Figure 2:
 
Figure 2: Editing Parameters
13.   Click OK and then OK again.
Repeat steps 11 to 13 for each Product type column, but selecting Product type1 as value for the drill through parameter. (Depending on the column title where the drill through is initiated from - we will assign the according value for the parameter that gives us the column to sort.)
14.   Save the report and from Run->Run Options... menu deselect Prompt and click OK.
15.   Run the report and test sorting by clicking on column headers.
To improve the report to allow dynamic ascending or descending sorting, you can follow these additional steps:
16.   In Query Explorer go to Query1.
17.   Double-click Sort_item_asc to edit it and type:
if (#prompt('p_Direction','integer','1')#=1)
then(
#prompt('p_SortColumn','token','[gosales_goretailers].[Products].[Product line]')#)
else ('0')
(1 means ascending and -1 means descending. We will have a data item that changes from 1 to -1 and vice-versa at each drill through.)

Click OK.
 
Figure 3: Create ascending sort
18.   Create a copy for Sort_item_asc (using CTRL+C and CTRL+V). Rename the copy to Sort_item_desc.
19.   Double-click Sort_item_desc to edit it and change =1 to =-1. Click OK.
 
Figure 4: Create Descending sort
20.   Go to Page1 and click anywhere in the list. From the menu select Data and then Advanced Sorting...
21.   Drag Sort_item_desc underneath Sort_item_asc in Detail Sort List folder and click on the Sort Order button to change it to descending.
 
Figure 5: Change sort order to descending
22.   Click OK.
23.   From Query Explorer click Query1 and add a Data Item from the toolbox. Type this in the expression editor:
-(#prompt('p_Direction','integer','1')#)
Click OK. (This data item is the future value of the sort order on the next drill through.)
 
Figure 6: Create expression definition
23.   Rename Data Item1 to Direction.
24.   Save the report.
25.   Change the drill through properties for Product line and Product type list column title to pass a data item value for p_Direction parameter, and for the Value select Direction.
 
Figure 7: Setting the parameters
26.   Click OK and then OK.
27.   Save the report and run. For each click on the column header the order changes from ascending to descending and vice-versa.
XML Report Specification
Attached is the XML Report Specification for this solution. Remember to save the report under the name Cognos Sorting or otherwise change the drill through property to point to the correct name.


« Last Edit: 28 Nov 2007 02:11:21 am by cognosjon »

Offline faris

  • Full Member
  • ***
  • Join Date: Nov 2007
  • Posts: 15
  • Forum Citizenship: +0/-0
Re: sorting columns by clicking headers
« Reply #7 on: 30 Nov 2007 07:58:28 am »
I tried HTML method. It is working well for one page. My report has 25 rows. in single page i can view 20 rows. the HTML method is working well for this 20 rows. How to implement it for all 25 rows?

Offline faris

  • Full Member
  • ***
  • Join Date: Nov 2007
  • Posts: 15
  • Forum Citizenship: +0/-0
Re: sorting columns by clicking headers
« Reply #8 on: 30 Nov 2007 07:59:54 am »
I tried the method (without HTML and javascript). I am getting the following error..
"An error occurred while performing operation 'sqlPrepareWithOptions' status='-16'."

Offline MFGF

  • Never knowingly correct
  • Super Moderator
  • Statesman
  • ******
  • Join Date: Jul 2005
  • Posts: 10,217
  • Forum Citizenship: +620/-10
  • Cognos Software Muppet
Re: sorting columns by clicking headers
« Reply #9 on: 30 Nov 2007 08:55:12 am »
Hi,

I tried HTML method. It is working well for one page. My report has 25 rows. in single page i can view 20 rows. the HTML method is working well for this 20 rows. How to implement it for all 25 rows?

Select the list object in your report, and set the number of rows per page to be 25.

Regards,

MF.
Meep!

Offline faris

  • Full Member
  • ***
  • Join Date: Nov 2007
  • Posts: 15
  • Forum Citizenship: +0/-0
Re: sorting columns by clicking headers
« Reply #10 on: 30 Nov 2007 11:03:21 pm »
I tried it.. it is working fine if i give the number of rows per page is 25..But unfortunately the requirement is, if the report contains 2 pages,clicking on column header should sort rows in both pages. Any idea?

Offline faris

  • Full Member
  • ***
  • Join Date: Nov 2007
  • Posts: 15
  • Forum Citizenship: +0/-0
Re: sorting columns by clicking headers
« Reply #11 on: 03 Dec 2007 12:13:59 am »
I tried the method of sorting columns without HTML object and javascript.It is working well for non-numeric columns.But for numeric columns it is throwing " 'sqlPrepareWithOptions' status='-16' " error.

Offline faris

  • Full Member
  • ***
  • Join Date: Nov 2007
  • Posts: 15
  • Forum Citizenship: +0/-0
got the solution
« Reply #12 on: 10 Dec 2007 11:10:38 pm »
Problem solved.. just replaced ['0'] by [null].. now it is working for both numeric and non-numeric columns.

Offline JO

  • Full Member
  • ***
  • Join Date: Aug 2005
  • Posts: 29
  • Forum Citizenship: +1/-1
Dynamic sorting columns in the cross tab report
« Reply #13 on: 15 Jul 2008 10:28:49 am »
Hi,

I have tried this solution in the list report . It is working fine. But my requirement in the cross tab report. Can some one help me on this?

Thanks
Jo

Offline fasi

  • Full Member
  • ***
  • Join Date: Nov 2006
  • Posts: 12
  • Forum Citizenship: +0/-1
Re: sorting columns by clicking headers
« Reply #14 on: 09 Jan 2009 10:10:16 pm »
Did any one have solution for this.

Sorting columns dynamically for cross tab.

Thanks,
Fasi.

 


       
Twittear