0

My Treepanel has the id 'treePanel' and works just fine.

Example path:

/subfolder3/abc

Expanding all with expandAll() works with the tree panel but expandPath() does not work.

Now, after some event I want to expand a path in my tree. However I can not make it.

So far I have tried:

var oTreePanel = Ext.getCmp('treePanel');

oTreePanel.expandPath('/subfolder3/abc'); // or '/subfolder3' or '/root/subfolder3'

There is no error message but also no change in the tree.

What to do?

EDIT

oTreePanel.selModel.getSelection()[0].getPath() is /root/.

What I tried:

  • path: /root => success is true and node says node.data.id="" and node.data.path=""

  • path: /root/ => success is true and node says node.data.id="" and node.data.path="/report_with_variables" (first node in the tree) and node.data.parentId= "root"

  • path: /root/subfolder3 to the path: success is false and node says node.data.id="" and node.data.path="" and node.getPath() is /root

My Json response for the tree looks like this:

{"status":{"status":0,"msg":"Ok","protocolversion":"extjs.json"},"value":{"name":"","path":"\/","type":"folder","leaf":false,"children":[{"name":"report_with_variables","path":"\/report_with_variables","type":"report","leaf":true,"title":"Report ohne Variablen","description":null},{"name":"subfolder1","path":"\/subfolder1","type":"folder","leaf":false},{"name":"subfolder2","path":"\/subfolder2","type":"folder","leaf":false},{"name":"subfolder3","path":"\/subfolder3","type":"folder","leaf":false},{"name":"testreports","path":"\/testreports","type":"folder","leaf":false}]}}
Shlomo
  • 3,880
  • 8
  • 50
  • 82

2 Answers2

3

expandPath works fine, try to verify the path you trying to expand. the path builds by default on node's model idProperty field, it is id property in the model data, maybe it is not the same as you are trying to use in the example.

  1. verify path and node's id
  2. try to run expandPath in the following format:

    tree.expandPath(path, null, null, function(success, node) { //analyse method execution
    });

    So you can analyse what is going on in the callback function:

    • if success is false and node is null then the path is empty

    • if success is false and node = root node than path is invalid in the very beginning

    • if success is false and node is not the root than the path is partially invalid

  3. try to get the path of some node in the tree using getPath() method and after it use obtained path with expandPath:

    var n = node.getPath(); tree.expandPath(path);

    it should work

babinik
  • 646
  • 3
  • 10
  • The problem is that Model has no id, you can add id field to the Model and return it from server side, or for example set Model's id to path field (it is not nice, there can be folders/files with the same name, but for test case you can try): `idProperty: 'path'` in the model for tree's store. It is because by default Model is used `id` name if `idProperty` configuration option is not specified – babinik Aug 31 '12 at 12:32
  • I tried the idProperty approach in the model but then the tree does not get loaded. Sorry I did not get it to work. – Shlomo Aug 31 '12 at 14:55
  • just try simple example http://jsfiddle.net/nbabinski/PF4Lu/1/ it create a tree (I just take it from ext examples) and expands a node in one second. Open the console to see the node's path. Maybe having the code snippet from you it will be easier to resolve the problem. in the example above it was not used model in the store, but in your code I think you are using one. Also in edit part you tried paths that is not correct according to your json data and default expandPath functionality, because it tries to expand nodes using their 'id' field. – babinik Aug 31 '12 at 16:38
  • Thanks for the help. The problem is the path and id – Shlomo Sep 03 '12 at 12:18
0

I had this same problem, and in my case the callback of expandPath was never called.

The reason was that the tree store was still loading a previous request when calling the expandPath method. Make sure your tree.store is not loading, before calling expandPath.

Maybe this helps you and/or others.

Allie
  • 1,081
  • 1
  • 13
  • 17