1. #1
    Sencha User
    Join Date
    Jul 2008
    Posts
    22
    Vote Rating
    0
    xmart2k is on a distinguished road

      0  

    Default Add node on a treepanel with direct proxy

    Add node on a treepanel with direct proxy


    Hello,

    I have a tree that is loading data with direct.
    My proxy is defined like this
    Code:
    proxy: {        type: 'direct',
            api : {
                read: data.readNodes,
                create: data.createNode
    
            },
            reader: {
                type:'json',
                root: 'data'
            }
            
        },
    I've managed to create a node for this tree with appendChild. My question is, how can I send to the server the new created node? so basically I want to send a request to createNode with details for the new node. Or maybe update the treestore?

    Thanks!

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,642
    Vote Rating
    899
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    When a non-left node is expanded, it should send a request with that node so you can load it's children.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Jul 2008
    Posts
    22
    Vote Rating
    0
    xmart2k is on a distinguished road

      0  

    Default


    Thanks for the response, but after I've read it, I understand that I was not very clear on what I want.
    My problem was that after adding the node, in client side, in the tree, I don't know how will a send the info to the server, to add it into the database.

    I've done some digging and found that after append, the node is added to the store and then probably I should use the store.sync(). But after I call the sync method i'm having an error: "fn is undefined". The error is in the method doRequest from the class Ext.data.proxy.Direct. Don't know why "if (operation.action == 'read')" is true, I was expecting to go on create.

    Thanks!

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,642
    Vote Rating
    899
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    So you add a node and call store.sync(). In your store's proxy, do you have the api setup so that the create is matched to a direct function?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  5. #5
    Sencha User
    Join Date
    Jul 2008
    Posts
    22
    Vote Rating
    0
    xmart2k is on a distinguished road

      0  

    Default


    yeap, this is my proxy
    Code:
    proxy: {        type: 'direct',
            api : {
                read: dataProvider.model.ProtectedEntitiesEPS.getADGroups,
                create: dataProvider.model.ProtectedEntitiesEPS.addNode
            },
            reader: {
                type:'json',
                root: 'data'
            }
            
        },

  6. #6
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,642
    Vote Rating
    899
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    It's telling me that addNode isn't resolvable. What happens when you type that function into the console?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  7. #7
    Sencha User
    Join Date
    Jul 2008
    Posts
    22
    Vote Rating
    0
    xmart2k is on a distinguished road

      0  

    Default


    I'm getting this error: "TypeError: fn is undefined"
    this is the code for the add method:
    Code:
    var tree = Ext.getCmp("myTree");var selectedNode = tree.getSelectionModel().getLastSelected(); 
    var newNode = {};
                
                newNode.text = "testNode";
                newNode.type = 275;
    
    
                
                var appNode = selectedNode.appendChild(newNode);
    
    
    var rec = tree.getStore().getUpdatedRecords();
    tree.getStore().sync();

  8. #8
    Sencha User
    Join Date
    Jul 2008
    Posts
    22
    Vote Rating
    0
    xmart2k is on a distinguished road

      0  

    Default


    ok, found my problem...the function for create was wrong.

    now the request is pointing to the create method, correctly, but at the server side I don't get any data from that node.

  9. #9
    Sencha User
    Join Date
    Jul 2008
    Posts
    22
    Vote Rating
    0
    xmart2k is on a distinguished road

      0  

    Default


    solved it...my mistake, I was pointing to another function

Thread Participants: 1