[CLOSED] [1.0] ColumTree using Checkbox with nodes

  1. #1

    [CLOSED] [1.0] ColumTree using Checkbox with nodes

    Hi, everyone .

    We have a simple problem with columntree. How can we use checkbox with nodes in columntree ?

    Regards.
    Last edited by geoffrey.mcgill; Sep 21, 2010 at 2:59 PM. Reason: [CLOSED]
  2. #2
    Hello!

    The ColumnTree is just an extension (not in ExtJS core). It has the own UI class which, unfortunately, doesn't support checkboxes.
    You could try to implement it extending the Ext.ux.tree.ColumnNodeUI class basing on Ext.tree.TreeNodeUI.


    Last edited by Daniil; Sep 08, 2010 at 4:18 PM.
  3. #3
    could you send a sample please ?

    Regards.
  4. #4
    Hi tansu,

    At this time the ColumnTree does not support Checkbox node indicators. We can add your request as a new "Feature Request" to be implemented in a future release.

    Unfortunately we do not have a sample available to demonstrate this functionality.
    Geoffrey McGill
    Founder
  5. #5
    hi geoffrey,
    we glad to see this feature in future release. now , we will try to find another solutions.

    thanks for concern.

    Regards.
  6. #6
    Hello!

    We are working on this.
    Here is a sample code.
    But it needs to fully test it before adding to the toolkit.
    You could use it and any feedback would be really appreciated.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
        <ext:ResourcePlaceHolder runat="server" />
    
        <script type="text/javascript">
            Ext.ux.tree.ColumnNodeUI.override({
                renderElements: function(n, a, targetNode, bulkRender) {
                    this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
    
                    var t = n.getOwnerTree(),
                        cols = t.columns,
                        bw = t.borderWidth,
                        c = cols[0],
                        cb = Ext.isBoolean(a.checked);
    
                    var buf = [
                        '<li class="x-tree-node"><div ext:tree-node-id="', n.id, '" class="x-tree-node-el x-tree-node-leaf ', a.cls, '">',
                        '<div class="x-tree-col" style="width:', c.width - bw, 'px;">',
                        '<span class="x-tree-node-indent">', this.indentMarkup, "</span>",
                        '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow">',
                        '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon', (a.icon ? " x-tree-node-inline-icon" : ""), (a.iconCls ? " " + a.iconCls : ""), '" unselectable="on">',
                        cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + (a.checked ? 'checked="checked" />' : '/>')) : '',     
                        '<a hidefocus="on" class="x-tree-node-anchor" href="', a.href ? a.href : "#", '" tabIndex="1" ',
                        a.hrefTarget ? ' target="' + a.hrefTarget + '"' : "", '>',
                        '<span unselectable="on">', n.text || (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]), "</span></a>",
                        "</div>"
                    ];
                    for (var i = 1, len = cols.length; i < len; i++) {
                        c = cols[i];
    
                        buf.push('<div class="x-tree-col ', (c.cls ? c.cls : ''), '" style="width:', c.width - bw, 'px;">',
                            '<div class="x-tree-col-text">', (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]), "</div>",
                          "</div>");
                    }
                    buf.push(
                        '<div class="x-clear"></div></div>',
                        '<ul class="x-tree-node-ct" style="display:none;"></ul>',
                        "</li>");
    
                    if (bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()) {
                        this.wrap = Ext.DomHelper.insertHtml("beforeBegin",
                                    n.nextSibling.ui.getEl(), buf.join(""));
                    } else {
                        this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
                    }
    
                    this.elNode = this.wrap.childNodes[0];
                    this.ctNode = this.wrap.childNodes[1];
                    var cs = this.elNode.firstChild.childNodes;
                    this.indentNode = cs[0];
                    this.ecNode = cs[1];
                    this.iconNode = cs[2];
                    var index = 3;                                                  
                    if (cb) {                                                       
                        this.checkbox = cs[3];                                      
                        // fix for IE6                                              
                        this.checkbox.defaultChecked = this.checkbox.checked;       
                        index++;                                                    
                    }
                    this.anchor = cs[index];
                    this.textNode = cs[index].firstChild;
                }
            });
        </script>
    
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:ColumnTree 
            ID="ColumnTree1" 
            runat="server" 
            RootVisible="false" 
            Title="Text ColumnTree"
            Width="350">
            <Columns>
                <ext:ColumnTreeColumn Header="Test" DataIndex="test" Width="200" />
                <ext:ColumnTreeColumn Header="Test2" DataIndex="test2" Width="100" />
            </Columns>
            <Loader>
                <ext:TreeLoader>
                    <UIProviders>
                        <ext:TreeNodeUIProvider Alias="col" ClassName="<%# ColumnTree.ColumnNodeUI %>" AutoDataBind="true" />
                    </UIProviders>
                </ext:TreeLoader>
            </Loader>
            <Root>
                <ext:TreeNode Text="test">
                    <Nodes>
                        <ext:TreeNode 
                            NodeID="TreeNode1" 
                            UIProvider="col" 
                            Leaf="true" 
                            Text="Leaf" 
                            Checked="True">
                            <CustomAttributes>
                                <ext:ConfigItem Name="test" Value="test" Mode="Value" />
                                <ext:ConfigItem Name="test2" Value="test2" Mode="Value" />
                            </CustomAttributes>
                            <Listeners>
                                <CheckChange Handler="alert('CheckChange event. NodeID: ' + this.id + ', Checked: ' + checked)" />
                            </Listeners>
                        </ext:TreeNode>
                    </Nodes>
                </ext:TreeNode>
            </Root>
            <Buttons>
                <ext:Button runat="server" Text="isChecked method">
                    <Listeners>
                        <Click Handler="alert(#{ColumnTree1}.getNodeById('TreeNode1').getUI().isChecked())" />
                    </Listeners>
                </ext:Button>
                <ext:Button runat="server" Text="toggleCheck method">
                    <Listeners>
                        <Click Handler="#{ColumnTree1}.getNodeById('TreeNode1').getUI().toggleCheck()" />
                    </Listeners>
                </ext:Button>
            </Buttons>
        </ext:ColumnTree>
        </form>
    </body>
    </html>
    To apply it to your ColumnTree please just add it to the <head> of your page.

    Example
    <ext:ResourcePlaceHolder runat="server" />
    
    <script type="text/javascript">
        Ext.ux.tree.ColumnNodeUI.override({
            renderElements: function(n, a, targetNode, bulkRender) {
                this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
    
                var t = n.getOwnerTree();
                var cols = t.columns;
                var bw = t.borderWidth;
                var c = cols[0];
                var cb = Ext.isBoolean(a.checked);
    
                var buf = [
                    '<li class="x-tree-node"><div ext:tree-node-id="', n.id, '" class="x-tree-node-el x-tree-node-leaf ', a.cls, '">',
                    '<div class="x-tree-col" style="width:', c.width - bw, 'px;">',
                    '<span class="x-tree-node-indent">', this.indentMarkup, "</span>",
                    '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow">',
                    '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon', (a.icon ? " x-tree-node-inline-icon" : ""), (a.iconCls ? " " + a.iconCls : ""), '" unselectable="on">',
                    cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + (a.checked ? 'checked="checked" />' : '/>')) : '',     
                    '<a hidefocus="on" class="x-tree-node-anchor" href="', a.href ? a.href : "#", '" tabIndex="1" ',
                    a.hrefTarget ? ' target="' + a.hrefTarget + '"' : "", '>',
                    '<span unselectable="on">', n.text || (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]), "</span></a>",
                    "</div>"
                ];
                for (var i = 1, len = cols.length; i < len; i++) {
                    c = cols[i];
    
                    buf.push('<div class="x-tree-col ', (c.cls ? c.cls : ''), '" style="width:', c.width - bw, 'px;">',
                        '<div class="x-tree-col-text">', (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]), "</div>",
                      "</div>");
                }
                buf.push(
                    '<div class="x-clear"></div></div>',
                    '<ul class="x-tree-node-ct" style="display:none;"></ul>',
                    "</li>");
    
                if (bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()) {
                    this.wrap = Ext.DomHelper.insertHtml("beforeBegin",
                                n.nextSibling.ui.getEl(), buf.join(""));
                } else {
                    this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
                }
    
                this.elNode = this.wrap.childNodes[0];
                this.ctNode = this.wrap.childNodes[1];
                var cs = this.elNode.firstChild.childNodes;
                this.indentNode = cs[0];
                this.ecNode = cs[1];
                this.iconNode = cs[2];
                var index = 3;                                                  
                if (cb) {                                                       
                    this.checkbox = cs[3];                                      
                    // fix for IE6                                              
                    this.checkbox.defaultChecked = this.checkbox.checked;       
                    index++;                                                    
                }
                this.anchor = cs[index];
                this.textNode = cs[index].firstChild;
            }
        });
    </script>
    Last edited by Daniil; Sep 15, 2010 at 8:58 PM. Reason: Minor code formatting
  7. #7
    Here is more complex example for testing purpose.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>ColumnTree with check nodes- Ext.NET Example</title>
        <ext:ResourcePlaceHolder runat="server" />
    
        <script type="text/javascript">
            Ext.ux.tree.ColumnNodeUI.override({
                renderElements: function(n, a, targetNode, bulkRender) {
                    this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
    
                    var t = n.getOwnerTree(),
                        cols = t.columns,
                        bw = t.borderWidth,
                        c = cols[0],
                        cb = Ext.isBoolean(a.checked),
                        buf = [
                            '<li class="x-tree-node"><div ext:tree-node-id="', n.id, '" class="x-tree-node-el x-tree-node-leaf ', a.cls, '">',
                            '<div class="x-tree-col" style="width:', c.width - bw, 'px;">',
                            '<span class="x-tree-node-indent">', this.indentMarkup, "</span>",
                            '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow">',
                            '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon', (a.icon ? " x-tree-node-inline-icon" : ""), (a.iconCls ? " " + a.iconCls : ""), '" unselectable="on">',
                            cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + (a.checked ? 'checked="checked" />' : '/>')) : '',
                            '<a hidefocus="on" class="x-tree-node-anchor" href="', a.href ? a.href : "#", '" tabIndex="1" ',
                            a.hrefTarget ? ' target="' + a.hrefTarget + '"' : "", '>',
                            '<span unselectable="on">', n.text || (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]), "</span></a>",
                            "</div>"
                        ];
                    for (var i = 1, len = cols.length; i < len; i++) {
                        c = cols[i];
    
                        buf.push('<div class="x-tree-col ', (c.cls ? c.cls : ''), '" style="width:', c.width - bw, 'px;">',
                            '<div class="x-tree-col-text">', (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]), "</div>",
                          "</div>");
                    }
                    buf.push(
                        '<div class="x-clear"></div></div>',
                        '<ul class="x-tree-node-ct" style="display:none;"></ul>',
                        "</li>");
    
                    if (bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()) {
                        this.wrap = Ext.DomHelper.insertHtml("beforeBegin",
                                    n.nextSibling.ui.getEl(), buf.join(""));
                    } else {
                        this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
                    }
    
                    this.elNode = this.wrap.childNodes[0];
                    this.ctNode = this.wrap.childNodes[1];
                    var cs = this.elNode.firstChild.childNodes;
                    this.indentNode = cs[0];
                    this.ecNode = cs[1];
                    this.iconNode = cs[2];
                    var index = 3;
                    if (cb) {
                        this.checkbox = cs[3];
                        // fix for IE6                                              
                        this.checkbox.defaultChecked = this.checkbox.checked;
                        index++;
                    }
                    this.anchor = cs[index];
                    this.textNode = cs[index].firstChild;
                }
            });
        </script>
    
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <h1>
            ColumnTree</h1>
        <ext:ColumnTree 
            ID="ColumnTree1" 
            runat="server" 
            Width="550" 
            Height="300" 
            RootVisible="false"
            AutoScroll="true" 
            Title="Example Tasks">
            <Columns>
                <ext:ColumnTreeColumn Header="Tasks" Width="330" DataIndex="Task" />
                <ext:ColumnTreeColumn Header="Duration" Width="100" DataIndex="Duration" />
                <ext:ColumnTreeColumn Header="Assigned To" Width="100" DataIndex="User" />
            </Columns>
            <Loader>
                <ext:TreeLoader>
                    <UIProviders>
                        <ext:TreeNodeUIProvider Alias="col" ClassName="<%# ColumnTree.ColumnNodeUI %>" AutoDataBind="true" />
                    </UIProviders>
                </ext:TreeLoader>
            </Loader>
            <Root>
                <ext:TreeNode Text="Tasks">
                    <Nodes>
                        <ext:TreeNode UIProvider="col" Icon="FolderGo" Checked="True">
                            <CustomAttributes>
                                <ext:ConfigItem Name="Task" Value="ColumnTree Example" Mode="Value" />
                                <ext:ConfigItem Name="Duration" Value="3 hours" Mode="Value" />
                                <ext:ConfigItem Name="User" Value="" Mode="Value" />
                            </CustomAttributes>
                            <Nodes>
                                <ext:TreeNode 
                                    UIProvider="col" 
                                    Icon="Cog" 
                                    Leaf="true" 
                                    Checked="True">
                                    <CustomAttributes>
                                        <ext:ConfigItem Name="Task" Value="Abstract rendering in TreeNodeUI" Mode="Value" />
                                        <ext:ConfigItem Name="Duration" Value="15 min" Mode="Value" />
                                        <ext:ConfigItem Name="User" Value="Core Team" Mode="Value" />
                                    </CustomAttributes>
                                </ext:TreeNode>
                                <ext:TreeNode 
                                    UIProvider="col" 
                                    Icon="Cog" 
                                    Leaf="true" 
                                    Checked="True">
                                    <CustomAttributes>
                                        <ext:ConfigItem Name="Task" Value="Create TreeNodeUI with column knowledge" Mode="Value" />
                                        <ext:ConfigItem Name="Duration" Value="45 min" Mode="Value" />
                                        <ext:ConfigItem Name="User" Value="Core Team" Mode="Value" />
                                    </CustomAttributes>
                                </ext:TreeNode>
                            </Nodes>
                        </ext:TreeNode>
                        <ext:TreeNode UIProvider="col" Icon="FolderGo" Checked="False">
                            <CustomAttributes>
                                <ext:ConfigItem Name="Task" Value="Custom Field Example" Mode="Value" />
                                <ext:ConfigItem Name="Duration" Value="2 1/2 hours" Mode="Value" />
                                <ext:ConfigItem Name="User" Value="" Mode="Value" />
                            </CustomAttributes>
                            <Nodes>
                                <ext:TreeNode 
                                    UIProvider="col" 
                                    Icon="Cog" 
                                    Leaf="true" 
                                    Checked="False">
                                    <CustomAttributes>
                                        <ext:ConfigItem Name="Task" Value="Implement 'Live Search' on extjs.com from Alex"
                                            Mode="Value" />
                                        <ext:ConfigItem Name="Duration" Value="1 hour" Mode="Value" />
                                        <ext:ConfigItem Name="User" Value="Core Team" Mode="Value" />
                                    </CustomAttributes>
                                </ext:TreeNode>
                                <ext:TreeNode 
                                    UIProvider="col" 
                                    Icon="Cog" 
                                    Leaf="true" 
                                    Checked="False">
                                    <CustomAttributes>
                                        <ext:ConfigItem Name="Task" Value="Extend TwinTrigger" Mode="Value" />
                                        <ext:ConfigItem Name="Duration" Value="30 min" Mode="Value" />
                                        <ext:ConfigItem Name="User" Value="Core Team" Mode="Value" />
                                    </CustomAttributes>
                                </ext:TreeNode>
                                <ext:TreeNode 
                                    UIProvider="col" 
                                    Icon="Cog" 
                                    Leaf="true" 
                                    Checked="False">
                                    <CustomAttributes>
                                        <ext:ConfigItem Name="Task" Value="Testing and debugging" Mode="Value" />
                                        <ext:ConfigItem Name="Duration" Value="1 hour" Mode="Value" />
                                        <ext:ConfigItem Name="User" Value="Core Team" Mode="Value" />
                                    </CustomAttributes>
                                </ext:TreeNode>
                            </Nodes>
                        </ext:TreeNode>
                    </Nodes>
                </ext:TreeNode>
            </Root>
            <Buttons>
                <ext:Button runat="server" Text="Is the selected node checked?">
                    <Listeners>
                        <Click Handler="alert(#{ColumnTree1}.getSelectionModel().getSelectedNode().getUI().isChecked())" />
                    </Listeners>
                </ext:Button>
                <ext:Button runat="server" Text="toggleCheck method">
                    <Listeners>
                        <Click Handler="#{ColumnTree1}.getRootNode().cascade(function(node) {node.getUI().toggleCheck() })" />
                    </Listeners>
                </ext:Button>
                <ext:Button runat="server" Text="Add CheckChange listener to selected node">
                    <Listeners>
                        <Click Handler="#{ColumnTree1}.getSelectionModel().getSelectedNode().on('checkchange', 
                                            function(node, checked) {
                                                Ext.Msg.alert('CheckChange event', 'checked: ' + checked);
                                            })" />
                    </Listeners>
                </ext:Button>
            </Buttons>
        </ext:ColumnTree>
        </form>
    </body>
    </html>
    Last edited by Daniil; Sep 21, 2010 at 3:02 PM.
  8. #8
    Hi,

    I'm marking this thread as [CLOSED]. We are investigating adding this functionality directly into a future release of the toolkit.
    Geoffrey McGill
    Founder

Similar Threads

  1. [CLOSED] Pre-Selecting gridpanel checkbox nodes..
    By PhilG in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jun 12, 2012, 8:29 AM
  2. TreePanel with Checkbox Enabled Nodes
    By original in forum 1.x Help
    Replies: 1
    Last Post: Nov 03, 2010, 8:26 PM
  3. Replies: 4
    Last Post: Oct 06, 2010, 9:08 AM
  4. [CLOSED] Dynamically create checkbox with AjaxEvent nodes
    By hillscottc in forum 1.x Legacy Premium Help
    Replies: 12
    Last Post: May 14, 2010, 5:33 PM
  5. [CLOSED] Adding Checkbox items to checkbox group during a postback?
    By vedagopal2004 in forum 1.x Legacy Premium Help
    Replies: 19
    Last Post: Feb 05, 2010, 10:13 AM

Tags for this Thread

Posting Permissions