cancel
Showing results for 
Search instead for 
Did you mean: 

How to delete dynamically created nodes?

Former Member
0 Kudos

Hello Colleagues,

In our screen we have a push button which adds one node to the context when used. The node is having a few fields which are shown in the UI.

So as you keep on pressing the button, additional rows will be appended on the screen.

Now, I have added another button on each of these rows. On clicking of which it should remove the row (the node). So each time you press the button 'Add element', additional rows will be appended, and each row will have a button 'Remove Element'.

But, the problem I am facing is in the implementation of 'Remove Element'.

The button 'Remove Element' is mapped to an action. But since there are as many 'Remove Element' buttons as there are rows, how do I identify which node is to be deleted ?

I have tried with get lead selection etc. but it didnt work.

Is there any way we can find out which UI element has trigerred the deletion, in the code of 'onactionSOMETHING' ?

Thanks

Gagan

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

In the onAction method of your 'Remove Element' button you can find the id of the button that was clicked.

The id of your remove element button and your node should be interlinked, so that it will be easier to identify. This should be kept in mind when you create your node and your button. For eg, when you create your first button, if the id is rb_1, your node should be smthing like node_1.

you can use the following piece of code to remove/delet your node

* Data declarations
  DATA: node_info TYPE REF TO if_wd_context_node_info,
        lt_nodes  TYPE wdr_context_child_info_map,
        ls_nodes  TYPE wdr_context_child_info.

* delete the node
  node_info = wd_context->get_node_info( ).
  lt_nodes = node_info->get_child_nodes( ).
  READ TABLE lt_nodes INTO ls_nodes WITH KEY name = 'NODE_1'. " your node name
  IF sy-subrc EQ 0.
    node_info->remove_child_node( name = 'NODE_1' ).
  ENDIF.

Radhika.

Former Member
0 Kudos

Hi Radhika,

The logic has already been done. Just I dont know how do I get the ID of the button that has triggered the action.

Regards

Gagan

Former Member
0 Kudos

Hi,

In the WDEVENT parameter of the action handler you can find the event id.

***Variables
  DATA:
    lv_selected  type string.          "Selected tab value
***Structure and internal table for the Events and messages
  DATA:
    lt_events type WDR_EVENT_PARAMETER_LIST,
    ls_events type WDR_EVENT_PARAMETER.

***Field symbols
  field-symbols: <fs_value> type any.   "Attribute value in events table

***Move the event table to lt_events
  lt_events = wdevent->parameters.


  read table  lt_events into ls_events with key name = 'SAVE'.  "Button Id
  if sy-subrc eq 0.
    assign ls_events-value->* to <fs_value>.
    if sy-subrc eq 0.
      lv_selected  = <fs_value>.
    endif.                 "IF sy-subrc eq 0.
  endif.                 "IF sy-subrc eq 0.

Regards,

Lekha.

Former Member
0 Kudos

Hi,

In the onAction method of the button.

data: id type string.
 " get button id
  id = wdevent->get_string( 'ID' ).

Radhika.

Former Member
0 Kudos

Hi Gagan,

Use the WDEVENT parameter to find out the clicked row index. The sample code is below:

DATA lo_el_X TYPE REF TO if_wd_context_element.
 
  DATA lv_index type i.
 
  "using the importing paramter WDEVENT, get the clicked index element
   lo_el_X = wdevent->get_context_element(
      name = 'CONTEXT_ELEMENT').
 
  " Here X is your context node name mapped to table
 
  "now using context_element u can get the index of selected row
 
   lv_index = lo_el_x->get_index( ).

Regards,

Manne.

Former Member
0 Kudos

Hi All,

Thanks for your help.

I am able to get the ID of the UI element now. The one that Radhika has mentioned runs fine. (I have not tried the other solutions!)

Regards.

Answers (0)