patternfly-bootstrap-treeview icon indicating copy to clipboard operation
patternfly-bootstrap-treeview copied to clipboard

Programmatically expanding a node from onNodeSelected event isn't working

Open ErnieAllen opened this issue 7 years ago • 11 comments

Not sure what I'm doing wrong. I'm trying to programmatically expand a node when the node is clicked (selected). The tree visually expands, but when I get a list of all the expanded nodes, the list is empty.

Please see the jsfiddle https://jsfiddle.net/acapkxhn/3/ Steps:

  • open a javascript console to see the log messages
  • click on the Parent 1 node The tree expands, but the list returned from tree.getExpanded() is empty.

I'm using

  • jquery 3.2.1
  • bootstrap 3.3.7
  • patternfly-bootstrap-treeview 2.1.5

Any idea what I'm doing wrong or not doing?

ErnieAllen avatar Nov 07 '17 12:11 ErnieAllen

Hi, I am also facing same issue. Any solution on this ?

ashishdeole avatar Dec 20 '17 13:12 ashishdeole

@ashishdeole, Sorry, I never did find a solution. What I ended up doing was using a different treeview control.

ErnieAllen avatar Dec 20 '17 13:12 ErnieAllen

@ErnieAllen and @ashishdeole the string concatenation in the demo works strange but if the event did not finish while running the callback, wrapping it around a setTimeout solves the issue:

var onTreeNodeSelected = function(x,y) {
  setTimeout(function() {
    // here goes your code
  });
};

skateman avatar Dec 20 '17 13:12 skateman

@skateman and @ashishdeole I updated the fiddle to call tree.expandNode(node) in a setTimeout. This didn't fix the problem.
The list returned from tree.getExpanded() is still empty. I also tried wrapping the code in the onTreeNodeExpanded event handler in a timeout, but that didn't work either. Here is the updated fiddle with the setTimeouts. https://jsfiddle.net/acapkxhn/6/

ErnieAllen avatar Dec 20 '17 14:12 ErnieAllen

Hm, strange ... it works for me. screenshot from 2017-12-20 15-19-31

skateman avatar Dec 20 '17 14:12 skateman

Also you don't need the second argument for the setTimeout, it's enough to put the function on the end of the execution queue.

skateman avatar Dec 20 '17 14:12 skateman

Sorry I wasn't clear in my description. When I click on the +, the tree is expanded automatically and the onTreeeNodeExpanded event hander is able to get the expanded list.

However, if I click on the text 'Parent 1', that is when the onTreeNodeSelected event is fired and I'm programmatically expanding the tree. In that case I'm not seeing the correct expanded list.

ErnieAllen avatar Dec 20 '17 14:12 ErnieAllen

@ErnieAllen strange, the workaround could be to set the expansion to silent and call the handler manually.

skateman avatar Dec 20 '17 14:12 skateman

@skateman I did what I think you suggested and no joy. https://jsfiddle.net/acapkxhn/7/ An extract of the pertinent part: tree.expandNode(node, {silent: true}) setTimeout( function () { onTreeNodeExpanded(e, node) }) The list returned by tree.getExpanded() is still empty after calling tree.expandNode(..)

ErnieAllen avatar Dec 20 '17 14:12 ErnieAllen

I will take a look into this after Christmas...

skateman avatar Dec 20 '17 14:12 skateman

Any updates please ?

ashishdeole avatar Jan 16 '18 11:01 ashishdeole