CL_GUI_ALV_GRID:在空网格中拖放?
CL_GUI_ALV_GRID: Drag and Drop in an empty grid?
我在我的一份报告中实施了拖放功能,当两个网格都填充了数据时,它实际上工作正常。当其中一个网格为空时,放置功能将被禁用。我怎样才能改变这个?
我用的是cl_gui_alv_grid
class.
您可以使用代表 ALV 网格控件其余部分的组件 cntr_ddid
:
go_table->set_table_for_first_display(
EXPORTING
is_layout = VALUE #(
s_dragdrop = VALUE #(
cntr_ddid = l_dragdrop_handle ) )
...
完整示例(您可以将行从顶部 table 拖放到底部 table,最初是空的——顶部 table 从 table SCARR
您可能需要调用程序 SAPBC_DATA_GENERATOR
--):
CLASS lcl_app DEFINITION.
PUBLIC SECTION.
METHODS main.
METHODS on_drag FOR EVENT ondrag OF cl_gui_alv_grid IMPORTING es_row_no e_dragdropobj.
METHODS on_drop FOR EVENT ondrop OF cl_gui_alv_grid.
PRIVATE SECTION.
DATA: go_split TYPE REF TO cl_gui_easy_splitter_container,
go_table1 TYPE REF TO cl_gui_alv_grid,
go_table2 TYPE REF TO cl_gui_alv_grid,
go_dragdrop1 TYPE REF TO cl_dragdrop,
go_dragdrop2 TYPE REF TO cl_dragdrop,
gt_scarr1 TYPE TABLE OF scarr,
gt_scarr2 TYPE TABLE OF scarr,
gs_scarr TYPE scarr.
ENDCLASS.
CLASS lcl_app IMPLEMENTATION.
METHOD main.
DATA: l_effect TYPE i,
l_dragdrop_handle1 TYPE i,
l_dragdrop_handle2 TYPE i.
go_split = NEW cl_gui_easy_splitter_container( parent = cl_gui_container=>screen0 ).
go_table1 = NEW cl_gui_alv_grid( i_parent = go_split->top_left_container ).
go_table2 = NEW cl_gui_alv_grid( i_parent = go_split->bottom_right_container ).
go_dragdrop1 = NEW cl_dragdrop( ).
go_dragdrop1->add(
flavor = 'DD1'
dragsrc = abap_true
droptarget = abap_false
effect = cl_dragdrop=>move ).
go_dragdrop2 = NEW cl_dragdrop( ).
go_dragdrop2->add(
flavor = 'DD1'
dragsrc = abap_false
droptarget = abap_true
effect = cl_dragdrop=>move ).
go_dragdrop1->get_handle( IMPORTING handle = l_dragdrop_handle1 ).
go_dragdrop2->get_handle( IMPORTING handle = l_dragdrop_handle2 ).
SELECT * FROM scarr INTO TABLE gt_scarr1.
go_table1->set_table_for_first_display(
EXPORTING
i_structure_name = 'SCARR'
is_layout = VALUE #(
s_dragdrop = VALUE #(
row_ddid = l_dragdrop_handle1 ) )
CHANGING
it_outtab = gt_scarr1 ).
go_table2->set_table_for_first_display(
EXPORTING
i_structure_name = 'SCARR'
is_layout = VALUE #(
s_dragdrop = VALUE #(
cntr_ddid = l_dragdrop_handle2 ) )
CHANGING
it_outtab = gt_scarr2 ).
SET HANDLER on_drag FOR go_table1.
SET HANDLER on_drop FOR go_table2.
ENDMETHOD.
METHOD on_drag.
DATA: lt_row TYPE lvc_t_roid.
FIELD-SYMBOLS:
<ls_row> TYPE lvc_s_roid.
go_table1->get_selected_rows( IMPORTING et_row_no = lt_row ).
READ TABLE gt_scarr1 INDEX lt_row[ 1 ]-row_id INTO gs_scarr.
e_dragdropobj->object = me. " dummy to trigger ON_DROP
ENDMETHOD.
METHOD on_drop.
APPEND gs_scarr TO gt_scarr2.
go_table2->refresh_table_display( is_stable = VALUE #( col = 'X' row = 'X' ) ).
ENDMETHOD.
ENDCLASS.
PARAMETERS p_dummy.
AT SELECTION-SCREEN OUTPUT.
NEW lcl_app( )->main( ).
我在我的一份报告中实施了拖放功能,当两个网格都填充了数据时,它实际上工作正常。当其中一个网格为空时,放置功能将被禁用。我怎样才能改变这个?
我用的是cl_gui_alv_grid
class.
您可以使用代表 ALV 网格控件其余部分的组件 cntr_ddid
:
go_table->set_table_for_first_display(
EXPORTING
is_layout = VALUE #(
s_dragdrop = VALUE #(
cntr_ddid = l_dragdrop_handle ) )
...
完整示例(您可以将行从顶部 table 拖放到底部 table,最初是空的——顶部 table 从 table SCARR
您可能需要调用程序 SAPBC_DATA_GENERATOR
--):
CLASS lcl_app DEFINITION.
PUBLIC SECTION.
METHODS main.
METHODS on_drag FOR EVENT ondrag OF cl_gui_alv_grid IMPORTING es_row_no e_dragdropobj.
METHODS on_drop FOR EVENT ondrop OF cl_gui_alv_grid.
PRIVATE SECTION.
DATA: go_split TYPE REF TO cl_gui_easy_splitter_container,
go_table1 TYPE REF TO cl_gui_alv_grid,
go_table2 TYPE REF TO cl_gui_alv_grid,
go_dragdrop1 TYPE REF TO cl_dragdrop,
go_dragdrop2 TYPE REF TO cl_dragdrop,
gt_scarr1 TYPE TABLE OF scarr,
gt_scarr2 TYPE TABLE OF scarr,
gs_scarr TYPE scarr.
ENDCLASS.
CLASS lcl_app IMPLEMENTATION.
METHOD main.
DATA: l_effect TYPE i,
l_dragdrop_handle1 TYPE i,
l_dragdrop_handle2 TYPE i.
go_split = NEW cl_gui_easy_splitter_container( parent = cl_gui_container=>screen0 ).
go_table1 = NEW cl_gui_alv_grid( i_parent = go_split->top_left_container ).
go_table2 = NEW cl_gui_alv_grid( i_parent = go_split->bottom_right_container ).
go_dragdrop1 = NEW cl_dragdrop( ).
go_dragdrop1->add(
flavor = 'DD1'
dragsrc = abap_true
droptarget = abap_false
effect = cl_dragdrop=>move ).
go_dragdrop2 = NEW cl_dragdrop( ).
go_dragdrop2->add(
flavor = 'DD1'
dragsrc = abap_false
droptarget = abap_true
effect = cl_dragdrop=>move ).
go_dragdrop1->get_handle( IMPORTING handle = l_dragdrop_handle1 ).
go_dragdrop2->get_handle( IMPORTING handle = l_dragdrop_handle2 ).
SELECT * FROM scarr INTO TABLE gt_scarr1.
go_table1->set_table_for_first_display(
EXPORTING
i_structure_name = 'SCARR'
is_layout = VALUE #(
s_dragdrop = VALUE #(
row_ddid = l_dragdrop_handle1 ) )
CHANGING
it_outtab = gt_scarr1 ).
go_table2->set_table_for_first_display(
EXPORTING
i_structure_name = 'SCARR'
is_layout = VALUE #(
s_dragdrop = VALUE #(
cntr_ddid = l_dragdrop_handle2 ) )
CHANGING
it_outtab = gt_scarr2 ).
SET HANDLER on_drag FOR go_table1.
SET HANDLER on_drop FOR go_table2.
ENDMETHOD.
METHOD on_drag.
DATA: lt_row TYPE lvc_t_roid.
FIELD-SYMBOLS:
<ls_row> TYPE lvc_s_roid.
go_table1->get_selected_rows( IMPORTING et_row_no = lt_row ).
READ TABLE gt_scarr1 INDEX lt_row[ 1 ]-row_id INTO gs_scarr.
e_dragdropobj->object = me. " dummy to trigger ON_DROP
ENDMETHOD.
METHOD on_drop.
APPEND gs_scarr TO gt_scarr2.
go_table2->refresh_table_display( is_stable = VALUE #( col = 'X' row = 'X' ) ).
ENDMETHOD.
ENDCLASS.
PARAMETERS p_dummy.
AT SELECTION-SCREEN OUTPUT.
NEW lcl_app( )->main( ).