Skip to Content

How do I know the level when I click an item in the tree?

Hi,

When I click a tree node in tree component, how do I know the level of this item?

E.g., if I click the root node, then I get the level number 1, if I click second level node, I get the number 2 etc.

Thanks!

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Best Answer
    Posted on Nov 22, 2005 at 05:24 AM

    if you need the level info when clicking the node you have to set the level values when filling the table TVIEW/TVIEW2 field TLEVEL with tree contents. Which you can read it later. the levels wont get filled/available automatically.

    Regards

    Raja

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Long Zheng

      HI,

      Are you transferring the XML data to be stored in some internal table?

      You can select the data after reading from the table into temporary internal tables and set the level(using ID) in the layout,based on the values of the table rows.

      As the data does not contain level detail,then you'l have to set the level yourself and then can read it as suggested earlier.

      Regards,

      Siddhartha

  • author's profile photo Former Member
    Former Member
    Posted on Nov 22, 2005 at 05:29 AM

    Hi,

    You can get to know the level of a tree by the ID of its node.

    Like,what i did was,In the layout,

    <htmlb:treeNode id      = "root"
                    text    = "MRF LIST"
                    isOpen  = "true">
       <htmlb:treeNode id      = "node1"
                       text    = "MRF's To Be Processed"
                       isOpen  = "true"
                       tooltip = "MRF's to do"
                       toggle  = "X">
    <%data :tab_0 type ZDI_MRF.%>
       <%loop at tab_mrf_0 into tab_0.%>
          <htmlb:treeNode id     = "node1<%=sy-tabix%>"
                          text   = "<%=tab_0-MRF_NUM%>"
                          image  = "@02@"
                          onNodeClick="show">
           </htmlb:treeNode>
        <% endloop.%>
    

    By this,on node click in onInputProcessing,we can process it as

    if  event->id = 'myTree1' and event->event_type = 'click'.
         data : t_event type ref to cl_htmlb_event_tree.
         t_event ?=  event.
         temp = t_event->node.
       <b>  if strlen( temp ) ge '6'. </b>
         data : x type string ,
                tab type zdi_mrf.
    
       <b>  if temp ca 'node1%'. </b>
                split temp at '1' into x node1.
              endif.

    By this you can get the length of the ID and hence get the level,say id strlen( temp ) = 4 ,then node = root ,if strlen( temp ) = 5 ,then level 1.

    Maybe you can do something similar.

    Hope this helps,

    Regards,

    Siddhartha

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 22, 2005 at 01:10 PM

    Hi,

    when you create the tree, you don't have to specify the level. It'S sufficient to set parentid and childid correctly.

    But of course, if you want to read it from the tree-table later, you have to set it before.

    An alternative is to write your own method that returns the level for a given childid. Try something like this:

    
    level = get_level( childid ).
    
    method get_level.
    * 1) get parentid for childid into lv_parent_id 
    * ...
    * 2) call this method recursively
    * IF current node is root
        rv_level = 1.
    * ELSE
        rv_level = get_level( lv_parent_id ) + 1.
    * ENDIF
    
    endmethod.
    

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.