[CLOSED] Send all treepanel nodes to directevent as extraparam

  1. #1

    [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.
     <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 5:00 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Please use .submitNodes() method.
    https://examples1.ext.net/#/TreePanel/Basic/Submit/
  3. #3
    Hi,

    Ypu can use serializeTree method
    <ext:Parameter Name="node" Value="#{TreeGrid1}.serializeTree()" Mode="Raw" />
    Regarding convertToSubmitNode method, if you need to get children also then pass config
    <ext:Parameter Name="node" Value="#{TreeGrid1}.convertToSubmitNode(#{TreeGrid1}.getSelectionModel().getSelectedNode(), {withChildren:true})" Mode="Raw" Encode="true"/>
    Last edited by Daniil; Mar 06, 2014 at 2:49 AM. Reason: Removed Encode="true"
  4. #4
    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:
    "{"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
    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
    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
  6. #6
    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):
    <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:
     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 18, 2012, 11:18 PM
  2. Replies: 2
    Last Post: Feb 28, 2012, 2:03 PM
  3. [CLOSED] Access TreeGrid nodes from DirectEvent handler
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 13
    Last Post: Jun 28, 2010, 6:35 PM
  4. Replies: 3
    Last Post: Mar 29, 2010, 9:10 AM
  5. Replies: 3
    Last Post: Oct 18, 2009, 7:03 AM

Tags for this Thread

Posting Permissions