Add Hidden Fields to OrgChart Node/Group Item

2 posts, 0 answers
  1. Mark
    Mark avatar
    1 posts
    Member since:
    Aug 2018

    Posted 09 Aug 2018 Link to this post

    Hi,

    I have created an OrgChart and added a rendered field using RadOrgChart.RenderedFields.ItemFields.Add().

    Is there a suitable way that I can add additional data to each Node/Group Item in the OrgChart without displaying it to the user and be able to access it from the client-side? Could this be done through a hidden field or through additional rendered fields?

    Thanks,

    Mark

  2. Peter Milchev
    Admin
    Peter Milchev avatar
    597 posts

    Posted 14 Aug 2018 Link to this post

    Hello Mark,

    If the information needed for the nodes is in the DataItem, you can access it in the item template as explained in https://docs.telerik.com/devtools/aspnet-ajax/controls/orgchart/templates/overview:

    <%# DataBinder.Eval(Container.DataItem, "Name")%>

    If you add the additional information in a HiddenField in the ItemTemplate, you can access it on the client-side as follows. 

    var valueOfHiddenField = $telerik.$(nodeClientSideObject._element).find("[id$='_AdditionalInfo']").val();

    <ItemTemplate>
        <span><%#Eval("EmployeeID")%></span>
        <br />
        <span><%#DataBinder.Eval(Container.DataItem, "ReportsTo")%></span>
        <br />
        <span><%#DataBinder.Eval(Container.DataItem, "FullName")%></span>
        <asp:HiddenField runat="server" ID="AdditionalInfo" Value=' <%#Eval("EmployeeID")%>' />
    </ItemTemplate>

    To access the HiddenField in the NodeDataBound event you can try this code: 

    protected void RadOrgChart1_NodeDataBound(object sender, OrgChartNodeDataBoundEventArguments e)
    {
        var node = e.Node;
        var hidden = node.Renderer.Controls[0].Controls[0].FindControl("AdditionalInfo") as HiddenField;
    }

    Regards,
    Peter Milchev
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top