Home » Developer & Programmer » Forms » sort display by clicking on head of column in forms
sort display by clicking on head of column in forms [message #86660] Mon, 18 October 2004 00:29 Go to next message
hudo
Messages: 165
Registered: May 2004
Senior Member
Is there a possibility in Forms to sort the table/display records by clicking
on the head of a certain column (maybe a PushButton) as it is possible in many Microsoft Software Products as Outlook, ...
Re: sort display by clicking on head of column in forms [message #86667 is a reply to message #86660] Mon, 18 October 2004 08:34 Go to previous messageGo to next message
rupa
Messages: 41
Registered: August 2002
Member
it is possible to do it but entire coding needs to be done to take care at the when button pressed trigger.
Re: sort display by clicking on head of column in forms [message #86670 is a reply to message #86667] Mon, 18 October 2004 10:48 Go to previous messageGo to next message
hudo
Messages: 165
Registered: May 2004
Senior Member
The output is based on a stored procedure. Above each output column there is a PushButton which sets the value of another TextItem (named: SORTORDER) by a WHEN-BUTTON-PRESSED Trigger. The value of :SORTBLOCK.SORTORDER is a input parameter MYSORTORDER of the stored procedure. A problem is at the moment, that the SELECT-statement in the stored procedure cannot be build dynamically and with the static variante of the stored procedure:
[
]
PROCEDURE display_emp (Resultset IN OUT EMP_CURSOR, MYSORTORDER VARCHAR2)
IS

l_sortorder VARCHAR2(20);
l_sql_stmt VARCHAR2(2000);

BEGIN

-- check innput parameters
--IF ( MYSORTORDER IS NULL ) THEN
--l_sortorder := 'EMPNO';
--ELSE
--l_sortorder := MYSORTORDER;
--END IF;

-- static variante without building sql_statement ---
OPEN Resultset
FOR
SELECT EMP.EMPNO EMPNO, EMP.ENAME ENAME , EMP.SAL SAL
FROM EMP
ORDER BY  MYSORTORDER;

--- alternative: Resultset with dynamic query ----
-- create dynamic query
--l_sql_stmt := 
--'SELECT EMP.EMPNO EMPNO, EMP.ENAME ENAME , EMP.SAL --SAL
--FROM EMP
--ORDER BY  '||l_sortorder;

--OPEN Resultset
--FOR  l_sql_stmt;

EXCEPTION
WHEN VALUE_ERROR THEN
NULL;
WHEN OTHERS THEN
NULL;

END display_emp;
END EMP_TOOLS;
[
]
the ORDER BY clause is not evaluated.

Any suggestions ?
Re: sort display by clicking on head of column in forms [message #86678 is a reply to message #86670] Tue, 19 October 2004 00:36 Go to previous messageGo to next message
Himanshu
Messages: 457
Registered: December 2001
Senior Member
Hudo,
There must be some syntax problem else the approach must work for you.
Make sure that the Name of columns you are passing from FORM to the Procedure are not the names of FORMS's columns and do not have Block name prefixed to them.

Here is a small smaple using Dynamic SQL:

PROCEDURE display_emp (Resultset IN OUT EMP_CURSOR, MYSORTORDER VARCHAR2)
IS

l_sortorder VARCHAR2(2000);
l_sql_stmt VARCHAR2(2000);

BEGIN

L_SQL_STMT:='SELECT EMP.EMPNO EMPNO, EMP.ENAME ENAME , EMP.SAL SAL FROM EMP'

-- check innput parameters
IF ( MYSORTORDER IS NULL ) THEN
l_sortorder := 'Order by EMP.EMPNO';
ELSE
l_sortorder := 'Order by '||MYSORTORDER';
END IF;

OPEN Resultset
FOR L_SQL_STMT||' '||l_sortorder;

-----

EXCEPTION
WHEN VALUE_ERROR THEN
NULL;
WHEN OTHERS THEN
NULL;

END display_emp;
END EMP_TOOLS;

This must work for you.
If not then check what is the string which is being formed in Stsmt & order by variables and try executing the statement on SQL prompt.You will find the problem if any.

HTH
Regards
Himanshu
Re: sort display by clicking on head of column in forms [message #86690 is a reply to message #86678] Tue, 19 October 2004 07:36 Go to previous message
rupa
Messages: 41
Registered: August 2002
Member
Hi,
This is one way you can do the sorting.
Create a program unit
procedure sort_proc
is
v_flg varchar2(10);
v_sort_col varchar2(100);
v_rec_id rowid;
begin
v_rec_id := block name.row_id;
v_sort_col := substr(:system.cursor_item,instr(:system.cursor_item,'.')+1);
v_sort_col := substr(v_sort_col,instr(v_sort_col,'_')+1);
If get_block_property(block name,order_by) = v_sort_col||' '||'Asc' then
v_flg='Desc';
elsif get_block_property(block name,order_by) = v_sort_col||' '||'Desc' then
v_flg = 'Asc';
elsif
v_lfg = 'Asc';
end if;
if v_flg = 'Asc' then
set_block_property(block name,order_by,v_sort_col||' '||'Asc');
execute_query;
else
set_block_property(blockname,order_by,v_sort_col||' '||'Desc');
execute_query;
First_Record;
loop
if v_rec_id = block name.row_id then
go_record(:system.cursor_record);
exit;
else
next_record;
end if;
if :system.last_record= 'TRUE' then
exit;
end if;
end loop;
end;
when button pressed call this procedure.
name the buttons on which the sort takes place as sort_<column name>.
make a hidden field of database yes, column rowid and name it as row_id.

on button pressed it will sort in asc if it was sorted in desc and vice versa. focus will remain on the same record.
Previous Topic: function keys press--- help me please
Next Topic: Diff between Object Libraries & PL/SQL Libraries
Goto Forum:
  


Current Time: Mon Sep 09 17:33:07 CDT 2024