This is a simple code I developed for incorporating sort feature for multi record block.
Block name :MY_BLOLCK
Fields: ID , DATE
Buttons: PB_ID, PB_DATE
1 When-New-Form-Instance
PRO_SET_LABEL ; -- to set button labels
2 CREATE BUTTONS for each database column and place it instead of the label in the multi record block.
3 In the When-Button-Pressed
BEGIN
PRO_SORT_DATA ;
END;
4 Create below 2 Procedures
a) PROCEDURE PRO_SET_LABEL IS
BEGIN
Set_Item_Property( 'MY_BLOCK.PB_ID', LABEL, 'ID Number' ) ;
Set_Item_Property( 'MY_BLOCK.PB_DATE', LABEL, 'Batch' || CHR(10) || 'Date' ) ;
-- Button label split into 2 lines
END;
b) PROCEDURE PRO_SORT_DATA
IS
lc_button_name VARCHAR2 (400) := :SYSTEM.TRIGGER_ITEM;
lc_ord_by_clause VARCHAR2 (400);
lc_item_id ITEM;
lc_button_label VARCHAR2 (400) := 'X';
lc_column_name VARCHAR2 (400);
BEGIN
IF GET_BLOCK_PROPERTY ('MY_BLOLCK', QUERY_HITS) > 0
THEN
lc_ord_by_clause :=
SUBSTR ('MY_BLOCK.PB_ID', 10, LENGTH ('MY_BLOCK.PB_ID') - 8) ;
-- Extract the item name
--All buttons are named with standard format so that button
--name can be extracted and used for database column/where clause.
lc_item_id := FIND_ITEM (lc_button_name);
PRO_SET_LABEL; --reset all button labels
lc_button_label := GET_ITEM_PROPERTY (lc_item_id, label);
lc_column_name := lc_ord_by_clause;
IF NVL (GET_BLOCK_PROPERTY ('MY_BLOLCK', ORDER_BY), 'X') =
lc_ord_by_clause || ' ASC'
THEN
SET_BLOCK_PROPERTY ('MY_BLOLCK',
ORDER_BY,
lc_ord_by_clause || ' DESC');
-- message( ' Inside ASC lc_ord_by_clause '|| lc_ord_by_clause );
-- message( ' Inside ASC lc_ord_by_clause '|| lc_ord_by_clause );
IF SUBSTR (lc_button_label, -1, 1) <> 'v'
THEN
IF SUBSTR (lc_button_label, -1, 1) = '^'
THEN
lc_button_label :=
SUBSTR (lc_button_label,
1,
(LENGTH (lc_button_label) - 1))
|| 'v';
SET_ITEM_PROPERTY (lc_item_id, label, lc_button_label);
ELSE
SET_ITEM_PROPERTY (lc_item_id, label, lc_button_label || ' v');
END IF;
END IF;
ELSE
SET_BLOCK_PROPERTY ('MY_BLOLCK',
ORDER_BY,
lc_ord_by_clause || ' ASC');
IF SUBSTR (GET_ITEM_PROPERTY (lc_button_name, label), -1, 1) <> '^'
THEN
IF SUBSTR (GET_ITEM_PROPERTY (lc_button_name, label), -1, 1) =
'v'
THEN
--message( ' Inside DESC lc_ord_by_clause '|| lc_ord_by_clause );
-- message( ' Inside DESC lc_ord_by_clause '|| lc_ord_by_clause );
lc_button_label :=
SUBSTR (lc_button_label,
1,
(LENGTH (lc_button_label) - 1))
|| '^';
--MESSAGE (' lc_button_label ' || lc_button_label);
-- MESSAGE (' lc_button_label ' || lc_button_label);
SET_ITEM_PROPERTY (lc_item_id, label, lc_button_label);
ELSE
SET_ITEM_PROPERTY (lc_item_id, label, lc_button_label || ' ^');
END IF;
END IF;
END IF;
EXECUTE_QUERY;
GO_ITEM (lc_button_name);
END IF;
END;
Best Regards
Rajesh Alex