我使用类CL_SALV_TREE
创建了一个ALV树视图。
一切正常,但我想抓住事件时,一个节点展开,填充一个函数,自动调整树列的大小。
我的问题是,扩展事件是CL_GUI_ALV_TREE
类的私有方法HANDLE_EXPAND_NC
,我实际上不知道如何捕获此事件。
据我所知,您只能被通知,如果文件夹被扩展,尚未包含子(_NC
部分的方法/事件名称表示)。这是为了延迟加载树。SAP菜单或IMG中显示的树就是一个很好的例子——当您展开顶级节点时,实际上可以看到树的某些部分正在加载。
如果这对您来说足够,请使用由CL_SALV_EVENTS_TREE
实现的接口IF_SALV_EVENTS_TREE
的事件EXPAND_EMPTY_FOLDER
。但是似乎没有一个好的演示程序。
这里是一个最小的可重复的例子,它显示事件EXPAND_EMPTY_FOLDER
是在您展开一个最初没有子节点时触发的,在该事件期间添加了一个子节点:
CLASS lcl_app DEFINITION.
PUBLIC SECTION.
METHODS pbo
RAISING
cx_salv_error.
PRIVATE SECTION.
DATA: salv TYPE REF TO cl_salv_tree,
scarrs TYPE STANDARD TABLE OF scarr.
METHODS on_expand_empty_folder
FOR EVENT expand_empty_folder
OF cl_salv_events_tree
IMPORTING node_key.
ENDCLASS.
CLASS lcl_app IMPLEMENTATION.
METHOD pbo.
IF salv IS NOT BOUND.
cl_salv_tree=>factory( EXPORTING r_container = cl_gui_container=>screen0
IMPORTING r_salv_tree = salv
CHANGING t_table = scarrs ).
DATA(lo_settings) = salv->get_tree_settings( ).
lo_settings->set_hierarchy_size( 30 ).
DATA(event) = salv->get_event( ).
salv->get_functions( )->add_function( name = 'NEW' text = 'NEW' tooltip = '' position = 1 ).
SET HANDLER on_expand_empty_folder FOR event.
SELECT * FROM scarr INTO TABLE @DATA(local_scarrs).
LOOP AT local_scarrs REFERENCE INTO DATA(scarr).
salv->get_nodes( )->add_node(
related_node = space " (root node)
relationship = cl_gui_column_tree=>relat_last_child
text = |{ scarr->carrid } - { scarr->carrname }|
data_row = scarr->*
folder = abap_true
expander = abap_true ).
ENDLOOP.
salv->display( ).
ENDIF.
LOOP AT SCREEN.
screen-active = '0'.
MODIFY SCREEN.
ENDLOOP.
ENDMETHOD.
METHOD on_expand_empty_folder.
TRY.
DATA(scarr) = CAST scarr( salv->get_nodes( )->get_node( node_key )->get_data_row( ) )->*.
salv->get_nodes( )->add_node(
related_node = node_key
relationship = cl_gui_column_tree=>relat_last_child
text = |Node added at time of expand below { scarr-carrid }| ).
CATCH cx_root INTO DATA(lx).
MESSAGE lx TYPE 'I' DISPLAY LIKE 'E'.
LEAVE PROGRAM.
ENDTRY.
ENDMETHOD.
ENDCLASS.
PARAMETERS dummy.
LOAD-OF-PROGRAM.
DATA(app) = NEW lcl_app( ).
AT SELECTION-SCREEN OUTPUT.
TRY.
app->pbo( ).
CATCH cx_root INTO DATA(lx).
MESSAGE lx TYPE 'S' DISPLAY LIKE 'E'.
ENDTRY.