[CLOSED] Treeview Click

  1. #1

    [CLOSED] Treeview Click

    Hello


    I made the code below that generates a dynamic treeview, I would put a click event running a function when the User click on the node.

            #region Criar os nodes filhos
            private Ext.Net.Node GetNodes(int Row, Ext.Net.Node treeNode)
            {
                TblmenuCollection coll = new TblmenuCollection();
                XPerfilPermissoesCollection pcoll = new XPerfilPermissoesCollection();
                XPerfilPermissoesQuery odq = new XPerfilPermissoesQuery("odq");
    
    
                TblmenuQuery oq = new TblmenuQuery("oq");
                oq.Select(oq.Idpai, oq.Id, oq.Menu, oq.Formulario, odq.Inclui, odq.Altera, odq.Exclui, odq.Idperfil, oq.Icone);
                oq.InnerJoin(odq).On(oq.Id == odq.Idmenu);
    
    
                oq.Where(odq.Visualiza == 1);
                oq.OrderBy(oq.Ordem.Ascending, oq.Idpai.Ascending);
                coll.Load(oq);
    
    
                var lst = from p in coll where p.Idpai == Row select p;
                foreach (Tblmenu fc in lst)
                {
                    Ext.Net.Node treeNode2 = new Ext.Net.Node();
                    treeNode2.NodeID = fc.Id.ToString();
                    treeNode2.Text = fc.Menu;
                    treeNode2.Qtip = fc.Menu;
                    treeNode2.NodeID = fc.Id.ToString();
    
    
                    if (!String.IsNullOrEmpty(fc.Icone))
                    {
                        Icon MeuIcone = ParseEnum<Icon>(fc.Icone);
                        treeNode2.Icon = MeuIcone;
    
    
                    }
                    if (!string.IsNullOrEmpty(fc.Formulario))
                    {
                        treeNode2.Href = this.Page.ResolveUrl(fc.Formulario);
                    }
                    var lst1 = from p in coll where p.Idpai == fc.Id select p;
                    if (lst1.Count() > 0)
                    {
                        GetNodes((Int32)fc.Id, treeNode2);
                        
                        //treeNode2.Listeners..DblClick.Handler = "addTab();";
                        //treeCadastro.Listeners.ItemClick.Handler = "addTab();";
                        treeNode2.Leaf = false;
                    }
                    else
                    {
                        treeNode2.Leaf = true;
                    }
    
    
    
    
                    treeNode.Children.Add(treeNode2);
    
    
                }
                return treeNode;
    
    
            }
            public static T ParseEnum<T>(string value)
            {
                return (T)Enum.Parse(typeof(T), value, true);
            }
    
    
            #endregion

    What should I do, I tried using Listerns, but I think I did it wrong because it did not work.

    Tks.
    Last edited by geoffrey.mcgill; Jul 08, 2014 at 3:58 AM. Reason: [CLOSED]
  2. #2
    You can investigate using the ItemClick event of the TreePanel or TreeView.

    http://docs.sencha.com/extjs/4.2.1/#...vent-itemclick

    Hope this helps.
    Geoffrey McGill
    Founder
  3. #3
    Let me know whether the following example helps you

    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
    
    <!DOCTYPE html>
    <html>
    <head id="Head1" runat="server">
        <script language="javascript">
            var itemClick = function (item, record, node, index, e) {
                alert(record.raw.url);
            }
        </script>
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager1" ScriptMode="Development" runat="server" />
        <ext:TreePanel  RootVisible="false" Title="Ext.Net" Height="700" Width="500" runat="server">
            <Store>
                <ext:TreeStore runat="server">
                    <Proxy>
                        <ext:AjaxProxy Url="/Example/LoadTreeFakeChildren">
                            <ActionMethods Read="POST" />
                            <Reader>
                                <ext:JsonReader Root="data" />
                            </Reader>
                        </ext:AjaxProxy>
                    </Proxy>
                    <Model>
                        <ext:Model ID="Model1" runat="server">
                            <Fields>
                                <ext:ModelField Name="Name" />
                                <ext:ModelField Name="Guid" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:TreeStore>
            </Store>
            <Root>
                <ext:Node NodeID="0" Text="Root" />
            </Root>
            <ColumnModel>
                <Columns>
                    <ext:TreeColumn Text="Name" DataIndex="Name" Flex="2" runat="server" />
                    <ext:Column Text="Guid" DataIndex="Guid" runat="server" />
                </Columns>
            </ColumnModel>
            <View>
                <ext:TreeView runat="server">
                    <Listeners>
                        <ItemClick Fn="itemClick" />
                    </Listeners>
                </ext:TreeView>
            </View>
        </ext:TreePanel>
    </body>
    </html>
    namespace RCNBS.Visions.SandBox.Controllers
    {
        public class ExampleController : System.Web.Mvc.Controller
        {
            public ActionResult Index()
            {
                return View();
            }
    
            public StoreResult LoadTreeFakeChildren()
            {
                NodeCollection nodes = new NodeCollection(false);
    
                for (int index = 1; index < 6; index++)
                {
                    Guid guid = Guid.NewGuid();
    
                    Node node = new Node
                    {
                        NodeID = index.ToString() + DateTime.Now.Second
                    };
    
                    node.CustomAttributes.Add(new ConfigItem { Name = "Name", Value = string.Format("Name {0}", node.NodeID), Mode = ParameterMode.Value });
                    node.CustomAttributes.Add(new ConfigItem { Name = "Guid", Value = guid.ToString(), Mode = ParameterMode.Value });
                    node.CustomAttributes.Add(new ConfigItem { Name = "url", Value = string.Format("https://www.google.com.br/search?q={0}", guid), Mode = ParameterMode.Value });
    
                    nodes.Add(node);
                }
    
                return new StoreResult
                {
                    Data = nodes.ToJson()
                };
            }
        }
    }
  4. #4
    Tks. Raphael..
  5. #5
    does it help you? can this thread be marked as closed?
  6. #6
    Yes, you can put as closed. Thank you
  7. #7
    Daniil or Geofrey, please mark this thread as closed.

Similar Threads

  1. Replies: 1
    Last Post: Apr 26, 2013, 6:28 PM
  2. Replies: 1
    Last Post: Aug 02, 2011, 12:59 PM
  3. [CLOSED] TreeView double click
    By majunior in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: May 10, 2011, 3:35 PM
  4. Replies: 0
    Last Post: May 02, 2010, 10:23 PM
  5. [CLOSED] Running function on node click in TreeView
    By Jurke in forum 1.x Legacy Premium Help
    Replies: 10
    Last Post: Jan 07, 2009, 5:58 PM

Posting Permissions