[CLOSED] Treepanel - Determine what column was clicked

  1. #1

    [CLOSED] Treepanel - Determine what column was clicked

    Hi there,

    I'm doing an upgrade to Ext.Net 2 and I had posted a question a while back about how to determine which column in a TreeGrid was click on:

    http://forums.ext.net/showthread.php...was-clicked-on

    Is there a way with the new TreePanel to do the same thing?

    Thank you.
    Last edited by Daniil; Dec 12, 2012 at 4:53 PM. Reason: [CLOSED]
  2. #2
    Hello!

    You can use CellClick event:

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>TreeGrid - Ext.NET Examples</title>
        
        <link href="/resources/css/examples.css" rel="stylesheet" />
        
        <script>
            var formatHours = function (v) {
                if (v < 1) {
                    return Math.round(v * 60) + " mins";
                } else if (Math.floor(v) !== v) {
                    var min = v - Math.floor(v);
                    return Math.floor(v) + "h " + Math.round(min * 60) + "m";
                } else {
                    return v + " hour" + (v === 1 ? "" : "s");
                }
            };
    
            var handler = function(grid, rowIndex, colIndex, actionItem, event, record, row) {
                Ext.Msg.alert('Editing' + (record.get('done') ? ' completed task' : '') , record.get('task'));
            };
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" SourceFormatting="True" ScriptMode="Debug" />
            
            <h1>
                TreeGrid Example
            </h1>
            <p>
                This example is an advanced tree example. It illustrates:
            </p>
            <ul class="feature-list">
                <li>Multiple headers
                </li>            
                <li>Header hiding, showing, reordering and resizing
                </li>
                <li>useArrows configuration
                </li>
                <li>Keyboard Navigation
                </li>
                <li>Discontinguous selection by holding the CTRL key
                </li>            
                <li>singleExpand has been set to true
                </li>
            </ul>
    
            <br />
    
            <ext:TreePanel 
                runat="server"
                Title="Core Team Projects"
                Width="500"
                Height="300"
                Collapsible="true"
                UseArrows="true"
                RootVisible="false"
                MultiSelect="true"
                SingleExpand="true"
                FolderSort="true">
                <Fields>
                    <ext:ModelField Name="task" />
                    <ext:ModelField Name="user" />
                    <ext:ModelField Name="duration" />
                    <ext:ModelField Name="done" Type="Boolean" />
                </Fields>
                <ColumnModel>
                    <Columns>
                        <ext:TreeColumn 
                            runat="server"
                            Text="Task" 
                            Flex="2" 
                            Sortable="true"
                            DataIndex="task" />
                        <ext:TemplateColumn 
                            runat="server"
                            Text="Duration" 
                            Flex="1"
                            Sortable="true" 
                            DataIndex="duration" 
                            Align="Center">                        
                            <Template runat="server">
                                <Html>
                                    {duration:this.formatHours}
                                </Html>
                                <Functions>
                                    <ext:JFunction Name="formatHours" Fn="formatHours" />
                                </Functions>
                            </Template>
                        </ext:TemplateColumn>
                        <ext:Column 
                            runat="server"
                            Text="Assigned To" 
                            Flex="1" 
                            Sortable="true"
                            DataIndex="user" />
                        <ext:CheckColumn runat="server" 
                           Text="Done"
                           DataIndex="done"
                           Width="40"
                           Editable="true"
                           StopSelection="false" />
                        <ext:ActionColumn runat="server" 
                            Text="Edit"
                            Width="40"
                            MenuDisabled="true"
                            Align="Center">
                            <Items>
                                <ext:ActionItem Tooltip="Edit task" Icon="PageWhiteEdit" Handler="handler">
                                    <IsDisabled Handler="return !record.data.leaf;" />
                                </ext:ActionItem>
                            </Items>    
                        </ext:ActionColumn>
                    </Columns>    
    
                </ColumnModel>
                
                <Root>
                    <ext:Node Text="Tasks">
                        <Children>
                            <ext:Node Icon="Folder" Expanded="true">
                                <CustomAttributes>
                                    <ext:ConfigItem Name="task" Value="Project: Shopping" Mode="Value" />
                                    <ext:ConfigItem Name="duration" Value="13.25" />
                                    <ext:ConfigItem Name="user" Value="Tommy Maintz" Mode="Value" />
                                </CustomAttributes>
                                <Children>
                                    <ext:Node Icon="Folder" Expanded="true">
                                        <CustomAttributes>
                                            <ext:ConfigItem Name="task" Value="Remodeling" Mode="Value" />
                                            <ext:ConfigItem Name="duration" Value="12" />
                                            <ext:ConfigItem Name="user" Value="Tommy Maintz" Mode="Value" />
                                        </CustomAttributes>
                                        <Children>
                                            <ext:Node Leaf="true">
                                                <CustomAttributes>
                                                    <ext:ConfigItem Name="task" Value="Retile kitchen" Mode="Value" />
                                                    <ext:ConfigItem Name="duration" Value="6.5" />
                                                    <ext:ConfigItem Name="user" Value="Tommy Maintz" Mode="Value" />
                                                </CustomAttributes>
                                            </ext:Node>
                                        </Children>
                                    </ext:Node>
                                </Children>
                            </ext:Node>
                        </Children>
                    </ext:Node>
                </Root>
                <Listeners>
                    <CellClick Handler="
                    // Check that it's not expander
                    if (!Ext.fly(e.getTarget()).hasCls('x-tree-expander'))
                        Ext.Msg.alert('Column index is ' + cellIndex);"></CellClick>
                </Listeners>
            </ext:TreePanel>        
        </form>
    </body>
    </html>
  3. #3
    Great - thank you.

Similar Threads

  1. [CLOSED] TreePanel with ContextMenu retrieve NodeID of node clicked
    By taylorjp2000 in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Nov 13, 2012, 3:17 PM
  2. [CLOSED] Treegrid - determine what column was clicked on
    By fordprefect in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 13, 2012, 5:12 PM
  3. Replies: 1
    Last Post: Nov 24, 2011, 6:48 AM
  4. Replies: 1
    Last Post: Sep 02, 2010, 3:59 PM
  5. Replies: 3
    Last Post: May 25, 2010, 4:29 PM

Tags for this Thread

Posting Permissions