Forum Stats

  • 3,769,338 Users
  • 2,252,950 Discussions
  • 7,874,992 Comments

Discussions

How to access Treeview by Javascript?

John like many others
John like many others Member Posts: 107 Red Ribbon
edited Aug 7, 2020 6:12AM in APEX Discussions

Hello

I have successfully created a hierarchy tree with the Treeview widget. On loading the page I can see the structure. This can change in the background so the user should be able to refresh it. In the documentation I've found the r"efresh" option::

$( "#HIERARCHYTREE" ).treeView( "refresh" );

So when the user presses a button I simply want the treeview refreshed. Instead of I get this error message:

desktop_all.min.js?v=19.2.0.00.18:2 Uncaught Error: cannot call methods on treeView prior to initialization; attempted to call method 'refresh'

    at Function.error (desktop_all.min.js?v=19.2.0.00.18:2)

    at HTMLDivElement.<anonymous> (desktop_all.min.js?v=19.2.0.00.18:27)

    at Function.each (desktop_all.min.js?v=19.2.0.00.18:2)

    at k.fn.init.each (desktop_all.min.js?v=19.2.0.00.18:2)

    at k.fn.init.a.fn.<computed> [as treeView] (desktop_all.min.js?v=19.2.0.00.18:27)

    at Object.javascriptFunction (f?p=107:25:106888120606339::::::246)

    at Object.da.doAction (desktop_all.min.js?v=19.2.0.00.18:21)

    at Object.da.doActions (desktop_all.min.js?v=19.2.0.00.18:21)

    at HTMLButtonElement.<anonymous> (desktop_all.min.js?v=19.2.0.00.18:21)

    at Function.each (desktop_all.min.js?v=19.2.0.00.18:2)

I assume the selector is correct. I set the value HIERARCHYTREE to the Static ID of the region "Widget", which holds the widget. Everything is there to rebuild the tree (no processes are going on). The refresh is triggered by a simple button (onclick). Any other try to access the treeview shows the same error message, i.e.:

var test= $("#HIERARCHYTREE").treeView("getExpandedNodeIds");

I couldn't find anything in the documentation that I'm doing wrong. I thought the simple access should be enough to refresh the tree view.

-> Working with Apex 19.2

Any help is appreciated!

Tagged:
John like many others

Answers

  • John like many others
    John like many others Member Posts: 107 Red Ribbon
    edited Jul 30, 2020 8:21AM

    I tried now also a treeview with "Hierarchy = not computed" in hope that this might work but I always got this error:

    Uncaught SyntaxError: Unexpected token ';'

    desktop_all.min.js?v=19.2.0.00.18:2 Uncaught ReferenceError: gTree130954677107061939Data is not defined

        at f?p=107:25:111531267707477::::::332

        at f?p=107:25:111531267707477::::::332

        at c (desktop_all.min.js?v=19.2.0.00.18:2)

        at Object.add [as done] (desktop_all.min.js?v=19.2.0.00.18:2)

        at HTMLDocument.<anonymous> (f?p=107:25:111531267707477::::::309)

        at Object.a.init (desktop_all.min.js?v=19.2.0.00.18:14)

        at HTMLDocument.<anonymous> (f?p=107:25:111531267707477::::::307)

        at e (desktop_all.min.js?v=19.2.0.00.18:2)

        at t (desktop_all.min.js?v=19.2.0.00.18:2)

    I can see an unnecessary ";" behind the related link that makes no sense to be there.

    I don't know how to proceed. The Treeview widget seems to be spiked with bugs.

  • John like many others
    John like many others Member Posts: 107 Red Ribbon
    edited Jul 30, 2020 10:10AM

    Could manage to create a very simple hierarchy with "Hierarchy = not computed" but in the end I got the same error message on trying to access the tree by Javascript:

    desktop_all.min.js?v=19.2.0.00.18:2 Uncaught Error: cannot call methods on treeView prior to initialization; attempted to call method 'refresh'

    @Apex team: Can you please check in Apex 18.2? I'm pretty sure this is a bug.

  • jmarc
    jmarc Member Posts: 399 Bronze Badge
    edited Aug 4, 2020 4:25AM

    hello,

    try

    apex.region("HIERARCHYTREE").widget().treeView("refresh");

    Expanding an Apex Tree Node on Entry

    jm

    John like many othersJohn like many others
  • John like many others
    John like many others Member Posts: 107 Red Ribbon
    edited Aug 7, 2020 6:12AM

    Hello jmarc

    Thanks a lot for your comment, which is very helpful! I can confirm that I don't get the error message again and "something" happens with the displayed hierarchy on refreshing it that way. I can't yet confirm that it's working as the HierarchyTree runs into another error on changing an item value (that is used on building different views of the Hierarchy, works atm only with the default value). As soon as this is working and I can see the different Hierarchy views I head back here, will show the solution (for others who may having the same problem) and accept your answer as the correct one.