IBI WebFOCUS - report column sorting using javascript
In our day to day
reporting projects, we might get some requirement where we need to give column sorting on the reports. Traditional
method is to give the recursive drill down on the title. In that case clicking
on the drilldown will open the same .fex file with some parameters to identify sort
logic and we get the sort logic done. The below code does the same thing
without reloading the report page. In the .fex file we use javascript code for sorting without reloading the entire page:
-* File test_sort.fex
-SET &ECHO=ALL;
-******************************************for
sorting******************************************************************
-DEFAULT
&sort_col = 'COUNTRY' ;
-DEFAULT
&sort_type = 0 ;
-SET &sort = IF
&sort_type EQ 1 THEN 'LOWEST' ELSE IF &sort_type EQ 2 THEN 'HIGHEST'
ELSE '' ;
-DEFAULT
&sort_col1 = 'COUNTRY' ;
-DEFAULT
&sort_type1 = 0 ;
-SET &sort1 = IF
&sort_type1 EQ 1 THEN 'LOWEST' ELSE IF &sort_type1 EQ 2 THEN 'HIGHEST'
ELSE '' ;
-DEFAULT
&sort_col2 = 'COUNTRY' ;
-DEFAULT
&sort_type2 = 0 ;
-SET &sort2 = IF
&sort_type2 EQ 1 THEN 'LOWEST' ELSE IF &sort_type2 EQ 2 THEN 'HIGHEST'
ELSE '' ;
-DEFAULT
&sort_col3 = 'COUNTRY' ;
-DEFAULT
&sort_type3 = 0 ;
-SET &sort3 = IF
&sort_type3 EQ 1 THEN 'LOWEST' ELSE IF &sort_type3 EQ 2 THEN 'HIGHEST'
ELSE '' ;
-DEFAULT
&sort_col4 = 'COUNTRY' ;
-DEFAULT
&sort_type4 = 0 ;
-SET &sort4 = IF
&sort_type4 EQ 1 THEN 'LOWEST' ELSE IF &sort_type4 EQ 2 THEN 'HIGHEST'
ELSE '' ;
-SET &col1 = IF
&sort_col EQ 'COUNTRY' THEN &sort_col | &sort_type ELSE 'COUNTRY0'
;
-SET &col2 = IF
&sort_col EQ 'CAR' THEN &sort_col | &sort_type ELSE 'CAR0' ;
-SET &col3 = IF
&sort_col EQ 'DEALER_COST' THEN &sort_col | &sort_type ELSE
'DEALER_COST0' ;
-SET &col4 = IF
&sort_col EQ 'RETAIL_COST' THEN &sort_col | &sort_type ELSE
'RETAIL_COST0' ;
-*-SET
&J='&J';
TABLE FILE CAR
PRINT COUNTRY AS
'<A href="javascript:sortReport1( ''&col1'' );
"TITLE="Click to sort in ascending or descending
order">Country</A>'
CAR AS '<A
href="javascript:sortReport1( ''&col2'' ); "TITLE="Click to
sort in ascending or descending order">Car</A>'
DEALER_COST AS '<A
href="javascript:sortReport1( ''&col3'' ); "TITLE="Click to
sort in ascending or descending order">Dealer cost</A>'
RETAIL_COST AS '<A
href="javascript:sortReport1( ''&col4'' ); "TITLE="Click to
sort in ascending or descending order">Retail cost</A>'
-IF &sort EQ ''
THEN SKL1 ELSE RPT1;
-RPT1
BY &sort.EVAL
&sort_col.EVAL NOPRINT
-SKL1
HEADING
"Sorting logic
using javascript(domain)"
"Note: The
report is POC for sorting logic using javascript and will not work for other
than HTML format"
ON TABLE PCHOLD
FORMAT HTML
ON TABLE SET PAGE-NUM
OFF
ON TABLE SET
BYDISPLAY ON
ON TABLE SET LINES
99999
ON TABLE SET HTMLCSS
ON
ON TABLE SET EMPTYREPORT
OFF
ON TABLE SET STYLE *
ENDSTYLE
ON TABLE HOLD AS
SORT_TEST FORMAT HTMTABLE
END
-RUN
-HTMLFORM BEGIN
<HTML>
<SCRIPT>
function sortReport1(
col ) {
col = String( col ) ;
var len = col.length ;
var sort = col.substring( len - 1 , len ) ;
if ( sort == 0 ) {
FRM1.sort_type.value = 1 ;
} else if ( sort == 1 ) {
FRM1.sort_type.value = 2 ;
} else {
FRM1.sort_type.value = 1 ;
}
FRM1.sort_col.value = col.substring( 0, len -
1 ) ;
-*alert(
FRM1.sort_col.value );
FRM1.submit();
return 0 ;
}
</SCRIPT>
<form method="POST"
action="/ibi_apps/WFServlet" NAME=FRM1 target=_self >
-*Below 3 lines should be enable for Standard environment of the report**********
-*<input
type="hidden" name="IBIF_ex"
value="test_sort.fex">
-*<input
type="hidden" name="IBIC_server"
value="EDASERVE">
-*<input
type="hidden" name="IBIAPP_app" value="psingh">
-*Below 3 lines should be enable for MRE with the details environment of the report**********
<input
type="hidden" name="IBIC_server" value="EDASERVE">
<input
type="hidden" name="IBIMR_drill" value="X,reportte/reportte.htm">
<input
type="hidden" name="IBIF_ex" value="app/test_sort1.fex">
<input
type="hidden" name="sort_col" value=!IBI.AMP.sort_col;>
<input
type="hidden" name="sort_type"
value=!IBI.AMP.sort_type;>
<input
type="hidden" name="sort_col1"
value=!IBI.AMP.sort_col1;>
<input
type="hidden" name="sort_type1"
value=!IBI.AMP.sort_type1;>
<input
type="hidden" name="sort_col2"
value=!IBI.AMP.sort_col2;>
<input
type="hidden" name="sort_type2"
value=!IBI.AMP.sort_type2;>
</head>
<body>
<table
border="0" id="table1">
<tr>
<td>!IBI.FIL.SORT_TEST;</td>
</tr>
</table>
</body>
</form>
<STYLE>
IMG {BORDER:0}
a:link
{color: blue;}
a:visited
{color: blue;}
a:hover
{color: blue;}
</STYLE>
</HTML>
-EXIT
You can copy the code to test_sort1.fex file and execute it with appropriate IBIAPP_app and IBIF_ex details.
Comments
Post a Comment