EXT.NET 3.0.0 RELEASED!
Now with Tablet Support!
Ext.NET 3.0.0 is here with lots of new cool features and now with tablet support! Check Examples Explorer now to see it in action or download and test it yourself for free!
Results 1 to 6 of 6

Thread: [CLOSED] Send all treepanel nodes to directevent as extraparam

  1. #1
    Member
    Join Date
    Nov 2010
    Posts
    12

    [CLOSED] Send all treepanel nodes to directevent as extraparam

    Hi,

    I have a page which includes an editable treepanel + other controls.

    I want everything to be saved in 1 directevent, but i don't know how to get all the treepanel nodes and add them as an extraparam.

    Can you help me out?

    I found this method in a previous post, but with this it's only possible to get 1 node.
    Code:
     <DirectEvents>
        <Click OnEvent="SubmitNode">
            <ExtraParams>
                <ext:Parameter Name="node" Value="#{TreeGrid1}.convertToSubmitNode(#{TreeGrid1}.getSelectionModel().getSelectedNode())" Mode="Raw" Encode="true"/>
            </ExtraParams>
        </Click>
    </DirectEvents>
    Let me know if you want an example.
    Last edited by Daniil; Feb 09, 2011 at 6:00 PM. Reason: [CLOSED]

  2. #2
    Ext.NET - Support Team Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    28,154
    Hi,

    Please use .submitNodes() method.
    http://examples1.ext.net/#/TreePanel/Basic/Submit/
    Daniil
    Ext.NET, Inc.
    Support Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  3. #3
    Ext.NET - Dev Team Vladimir's Avatar
    Join Date
    Mar 2008
    Location
    Russia
    Posts
    15,388
    Hi,

    Ypu can use serializeTree method
    Code:
    <ext:Parameter Name="node" Value="#{TreeGrid1}.serializeTree()" Mode="Raw" />
    Regarding convertToSubmitNode method, if you need to get children also then pass config
    Code:
    <ext:Parameter Name="node" Value="#{TreeGrid1}.convertToSubmitNode(#{TreeGrid1}.getSelectionModel().getSelectedNode(), {withChildren:true})" Mode="Raw" Encode="true"/>
    Last edited by Daniil; Mar 06, 2014 at 3:49 AM. Reason: Removed Encode="true"
    Vladimir Shcheglov
    Ext.NET, Inc.
    Development Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  4. #4
    Member
    Join Date
    Nov 2010
    Posts
    12
    Thank you both for the quick reply.

    @Daniil
    I don't think i can use the submitNodes, because i want 1 directmethod to include treepanel+other controls suchs as textboxes etc.
    Or am i wrong?

    @Vladimir
    This seems to work but i don't get all the attributes of the nodes.
    Example of serialized node data in code-behind:
    Code:
    "{"nodeID":"2","text":"Page text","path":"/1/2"}"
    As you can see, the "path" attribute contains invalid data.
    Could there be something wrong with the method, or is this by design?

  5. #5
    Ext.NET - Dev Team Vladimir's Avatar
    Join Date
    Mar 2008
    Location
    Russia
    Posts
    15,388
    Hi,

    I don't think i can use the submitNodes, because i want 1 directmethod to include treepanel+other controls suchs as textboxes etc.
    Or am i wrong?
    All fields will be submitted automatically by default.

    This seems to work but i don't get all the attributes of the nodes.
    What attributes are missed? Serializing doesn't include some standard attributes, you can write own filter function to include all attributes
    Code:
    tree.serializeTree({attributeFilter: function (attrName, attrValue) {
            return typeof attrValue != "function" && youFuncToDermineIfAttrIsAllowed(attrName);
        }
    })
    As you can see, the "path" attribute contains invalid data.
    Why do you think that value of path is invalid? What do you expect in the path? Path, by default, consist of nodes ids

    Please provide your test sample which demonstrate your scenario. Please provide which data do you expect to see in the serialized data
    Vladimir Shcheglov
    Ext.NET, Inc.
    Development Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  6. #6
    Member
    Join Date
    Nov 2010
    Posts
    12
    Ahh sorry, i didn't know about the attributefilter - and for some reason i thought path should contain the url. :(

    Anyways, i got it working with the serializeTree function.

    For people interested:
    Button to save my page info (simplified):
    Code:
    <ext:Button runat="server" Icon="DiskUpload" Scale="Small"  Text="Save"  >
    <DirectEvents>
        <Click  OnEvent="Save_Click">
            <ExtraParams>
                <ext:Parameter Name="nodes" 
                    Value="#{TreePanel1}.serializeTree({withChildren:true, attributeFilter: function (attrName, attrValue) {
                    return typeof attrValue!='function' && attrName!='children';}})" Mode="Raw" Encode="false"/>
            </ExtraParams>
        </Click>
    </DirectEvents>
    </ext:Button>
    Code-behind to save treepanel to DB:
    Code:
     Public Sub Save_Click(ByVal sender As Object, ByVal e As DirectEventArgs)
            Using DC As New DataContext
                Dim siteMapNodes = e.ExtraParams("nodes")
                Dim node As Newtonsoft.Json.Linq.JObject = JSON.Deserialize(Of Newtonsoft.Json.Linq.JObject)(siteMapNodes)
                SiteMapUpdate(node.Root, DC)
            End Using
        End Sub
    
        Protected Sub SiteMapUpdate(ByVal t As Newtonsoft.Json.Linq.JToken, ByVal DC As DataContext)
            Dim id = t.Value(Of Integer)("nodeID")
            Dim title = t.Value(Of String)("text")
            Dim descr = t.SelectToken("attributes").Value(Of String)("qtip")
            Dim url = t.SelectToken("attributes").Value(Of String)("href")
            Dim path = t.Value(Of String)("path")
            Dim isFolder = t.SelectToken("attributes").Value(Of Boolean)("isFolder")
            Dim children = t.SelectToken("children")
    
            DC.proc_SiteMapUpdate(id, title, descr, url, Nothing, Nothing)
    
            If children IsNot Nothing Then
                For Each v In children
                    SiteMapUpdate(v, DC)
                Next
            End If
        End Sub

    Thanks alot for the assistance!:)

Similar Threads

  1. Pass GridPanel or Store via DirectEvent/ExtraParam
    By slonati_adv in forum 2.x Help
    Replies: 1
    Last Post: Jun 19, 2012, 12:18 AM
  2. Replies: 2
    Last Post: Feb 28, 2012, 3:03 PM
  3. [CLOSED] Access TreeGrid nodes from DirectEvent handler
    By jmcantrell in forum 1.x Premium Help
    Replies: 13
    Last Post: Jun 28, 2010, 7:35 PM
  4. Replies: 3
    Last Post: Mar 29, 2010, 10:10 AM
  5. Replies: 3
    Last Post: Oct 18, 2009, 8:03 AM

Tags for this Thread

Posting Permissions