7

I need to reload a tree after deleting one of the leafs of a node. The problem of reloading the entire store is, it's too slow. That's why I just want to reload a node where its leaf is deleted.

I tried this.. but it says null...

Ext.getCmp('myTree').root.reload();

I also tried

var tempParent = Ext.getCmp('myTree').getSelectionModel().getSelection()[0].parentNode;
Ext.StoreMgr.lookup('myStore').load( {node: tempParent});

this doesn't help either... Does anyone have similar issues that's been solved?

Update

var node = Ext.getCmp('myTree').getSelectionModel().getSelection()[0].parentNode.get('id');

this does give me the parent node... but When I load it

Ext.getCmp('myTree').store.load({ node: node });

I get this error

TypeError: b.getId is not a function

Second Update--

This is what my tree looks like

  • 1st Node

    • 1st Leaf
  • 2nd Node

    • 1st Leaf

Now when I delete the 1st Leaf of the 2nd Node... the 1st Node appears under 2nd Node

  • 1st Node

    • 1st Leaf
  • 2nd Node

    • 1st Node
EagleFox
  • 1,367
  • 10
  • 34
  • 58
  • Is the tree bound to a store? Could you give a bit more information on why you need to reload the parent node? ExtJs would generally handle this correctly without you having to do anything. – Izhaki Jan 08 '13 at 10:58
  • Thanks Izhaki... I have a delete leaf function on my tree... and there can be multiple same leafs(let's say there can be 2 'leaf1')... so when I delete on 'leaf1', only the selected 'leaf1' gets deleted.. the second 'leaf1' is still on the tree... but when I manually refresh the browser, it's gone – EagleFox Jan 08 '13 at 13:54
  • 1
    And can't you just listen for node removal; find related nodes; and delete them as well? – Izhaki Jan 08 '13 at 16:43
  • That's exactly that I am trying to do... find related nodes... and I can't seem to wrap my head around it... could you please show me some samples – EagleFox Jan 08 '13 at 17:47
  • I updated my answer below. – dbrin Jan 23 '13 at 18:45

1 Answers1

6

Here is how to refresh a specific node of a tree. In your case you may want to refresh a parent node under which changes need to be shown:

   refreshRow:function(id){
        var node = this.store.getNodeById(id);
        if (node){
            this.store.load({node:node});
        }
     }

Update

Based on the information you provided my conclusion is that you are trying to populate the same Node with a specific server generated ID in several places in a Tree. The tree store does not support this. Each node must have a unique ID even if the the rest of the Node information is the same.

dbrin
  • 15,525
  • 4
  • 56
  • 83
  • Thanks dbrin... is this refreshRow inside beforedrop config? because I tried to do it after an ajax failure fn and it says getNodeyByid is not a function – EagleFox Jan 09 '13 at 19:27
  • probably because ajax callback is in windows scope. Change the code to get a reference to the store of the tree panel. – dbrin Jan 09 '13 at 19:42
  • Yes Dbrin.. I used Ext.getCmp.getSelectionModel().getSelection()[0].getNodeById(id) and I still get the same error... however doing parentNode.get('id') works. it gives me the node but it says TypeError: b.getId is not a function on load – EagleFox Jan 09 '13 at 20:08
  • getNodeById is a function on the store :: store.getNodeById(id); – dbrin Jan 09 '13 at 21:19
  • Well... :)... now it refreshes the node but then loads the first node of the tree on that node where the delete was done... and I also get this error TypeError: a[b] is undefined – EagleFox Jan 09 '13 at 21:34
  • sorry i didn't follow that. there are probably other issues. The code above is tested and works in production. – dbrin Jan 09 '13 at 21:52
  • dbrin... please see my 2nd update... it seems to work but why does my first node of the tree shows up on that node – EagleFox Jan 09 '13 at 22:02