cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Hierarchy isExpanded and how to delete the child nodes

Former Member
0 Kudos

Hi Friends,

Currently am working on a Table Hierarchy(TreeByKeyTableColumn)....here when the user clicks on root node I wil call the FM/Class for the backend call and I will generate(fill) the child nodes.For the time being did with some dummy data..please see the below code

INIT():

    DATA lo_nd_table_data_source TYPE REF TO if_wd_context_node.

    DATA lo_el_table_data_source TYPE REF TO if_wd_context_element.
    DATA ls_table_data_source TYPE wd_this->Element_table_data_source.

*   navigate from <CONTEXT> to <TABLE_DATA_SOURCE> via lead selection
    lo_nd_table_data_source = wd_context->get_child_node( name = wd_this->wdctx_table_data_source ).


*   get element via lead selection
    lo_el_table_data_source = lo_nd_table_data_source->get_element( ).

data:
    lt_rows type if_main=>elements_table_data_source,
    row     like line of lt_rows,
    IT_Asset TYPE ZAssetView .

IT_ASSET-ROW_KEY = 'WWU'.
    IT_ASSET-PARENT_ROW_KEY = ''.
    IT_ASSET-TREE_COLUMN_TEXT = 'WWU'.
    IT_ASSET-TABLE_COLUMN_1_T = ''.
    IT_ASSET-IS_LEAF = abap_false .

    APPEND IT_ASSET TO IT_Asset1 .

    IT_ASSET-ROW_KEY = 'WS'.
    IT_ASSET-PARENT_ROW_KEY = 'WWU'.
    IT_ASSET-TREE_COLUMN_TEXT = 'WS'.
    IT_ASSET-TABLE_COLUMN_1_T = 'Wales South'.
    IT_ASSET-IS_LEAF = abap_false .

    APPEND IT_ASSET TO IT_Asset1 .

*
   lo_nd_table_data_source->bind_table( new_items = IT_Asset1 ).


    lo_el_table_data_source = lo_nd_table_data_source->get_element( ).

The above code will generate a static hierarchy when they click on the above generated nodes,am generating a child nodes based on the clicked parent node 3 times....please see the below code in OnLoadChildren()

do 3 times.
*   save the index so that we can use it in deeper levels
    lvl1_index = var1.
    lvl2_index = sy-index.
    condense lvl2_index.

    concatenate lvl1_index `.` lvl2_index into LS_ASSETIT-row_key.
    LS_ASSETIT-PARENT_ROW_KEY = lvl1_index.
    LS_ASSETIT-TABLE_COLUMN_1_T = 'RAJESHlv_id'.
    concatenate lvl1_index `.` lvl2_index into LS_ASSETIT-TREE_COLUMN_TEXT .
    LS_ASSETIT-IS_LEAF = ABAP_FALSE .
    insert ls_AssetIT into table it .

    ENDDO.
    ENDIF.

    lo_nd_your_node->bind_table( new_items = it SET_INITIAL_ELEMENTS = ABAP_FALSE ).
    CLEAR IT.

   lo_nd_your_node->SET_LEAD_SELECTION_INDEX( -1 ).

    .
ENDIF.

* Note : Please go through the attachment with screeen shots will give a better idea

Upto here its absolutely fine, but the issue am facing is .. when I open a node its generating 3child node as per the logic above... and when I close and reopen its generating again (getting 6nodes , with duplicate nodes)..so how can I know when I open  a node is already opened ?....

And please let me know is there any way that I can delete a child nodes which generated on based of a particular parent-key.

Your suggestions and toughts a really helps to me.

Regards

Rajesh

Accepted Solutions (1)

Accepted Solutions (1)

former_member213957
Participant
0 Kudos

Hi Raj,

yaa.. its a silly mistake is you forgot to clear the internal table and indexes in the onloadchildren method.Do it.

I thought its works fine!!

Regards,

Kishorekumar

Former Member
0 Kudos

I cleared and refered my IT and WA even though its not working, Filling the nodes code I placed in a separate method and am calling that method in onLoadChildren ...so its automatically IT is getting refreshed.

I just done it by puting a flag like WDY_BOOLEAN and i checked before calling the Fillnodes () methods is its not open than am filling the data and making the flag 'Y'

Thanks for the replies.

Regards

Rajesh

Answers (1)

Answers (1)

Former Member
0 Kudos

You have to refresh your internal table.

REFRESH IT . " Refresh your ITAB before starting the loop

do 3 times.
*   save the index so that we can use it in deeper levels
    lvl1_index = var1.
    lvl2_index = sy-index.
    condense lvl2_index.

    concatenate lvl1_index `.` lvl2_index into LS_ASSETIT-row_key.
    LS_ASSETIT-PARENT_ROW_KEY = lvl1_index.
    LS_ASSETIT-TABLE_COLUMN_1_T = 'RAJESHlv_id'.
    concatenate lvl1_index `.` lvl2_index into LS_ASSETIT-TREE_COLUMN_TEXT .
    LS_ASSETIT-IS_LEAF = ABAP_FALSE .
    insert ls_AssetIT into table it .

    ENDDO.
    ENDIF.

    lo_nd_your_node->bind_table( new_items = it SET_INITIAL_ELEMENTS = ABAP_FALSE ).
    CLEAR IT.

   lo_nd_your_node->SET_LEAD_SELECTION_INDEX( -1 ).

    .
ENDIF

Former Member
0 Kudos

Hi Updendra ,

I need a help to add the child node to the parent node in Hierarchy from the table event, when I select some parent(WS.2.2) node from hierarchy it will open a pop up window with table , when user select the record from the table and click on OK button ,that selected record from the table should add like a child node to the selected parent node(WS.2.2) in the hierarchy.

I created a action action event and wrote the code in that ,if I call the 

ONACTIONTREEONLODCHID() (this is the one I created for Onloadchildren)...will that helps me ..if not please share your suggestions.

Regards

Rajesh