[CLOSED] Inherit CommandColumn

  1. #1

    [CLOSED] Inherit CommandColumn

    Hi,

    I have many CommandColumn that are exactly the same thru my code. So, I am trying to create a class that extends command column.

    So can I do this?

    Thanks

                    <ext:CommandColumn Header="Excluir" Width="45">
                        <Commands>
                            <ext:GridCommand CommandName="Excluir" Icon="Cross">
                                <ToolTip Text="Excluir" />
                            </ext:GridCommand>
                        </Commands>
                    </ext:CommandColumn>
    Class that I tried to do:

    using System;
    
    namespace Dojo.Control
    {
        sealed public class CommandColumn : Ext.Net.CommandColumn
        {
            public string Type { get; set; }
    
            public CommandColumn()
            {
                //if (Type == "Editar")
                //{
                //    Header = "Editar";
                //    Width = 45;
    
                //    Commands.Add(new GridCommand{CommandName = "Editar", Icon = Icon.Pencil});
                //    //ToolTip = new SimpleToolTip{Text = "Editar"}
                //}
            }
    
            protected override void OnDataBinding(EventArgs e)
            {
                //if (Type == "Editar")
                //{
                //    Header = "Editar";
                //    Width = 45;
    
                //    Commands.Add(new GridCommand { CommandName = "Editar", Icon = Icon.Pencil });
                //    //ToolTip = new SimpleToolTip{Text = "Editar"}
                //}
            }
    
    
            //        <ext:CommandColumn Header="Editar" Width="45">
                    //    <Commands>
                    //        <ext:GridCommand CommandName="Editar" Icon="Pencil">
                    //            <ToolTip Text="Editar" />
                    //        </ext:GridCommand>
                    //    </Commands>
                    //</ext:CommandColumn>
        }
    }
    Last edited by Daniil; Mar 02, 2011 at 3:17 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Please look at the example.

    Example Page
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <%@ Register Assembly="Work" Namespace="Work" TagPrefix="cc" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] {"test1"},
                    new object[] {"test2"},
                    new object[] {"test3"}
                };
                store.DataBind();
            }
        }
    </script>
    
    <!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>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
            <Store>
                <ext:Store runat="server">
                    <Reader>
                        <ext:ArrayReader>
                            <Fields>
                                <ext:RecordField Name="test" />
                            </Fields>
                        </ext:ArrayReader>
                    </Reader>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column Header="Test" DataIndex="test" />
                    <cc:MyCommandColumn />
                </Columns>
            </ColumnModel>
            <Listeners>
                <Command Handler="if (command = 'test') { alert(record.data.test); }" />
            </Listeners>
        </ext:GridPanel>
        </form>
    </body>
    </html>
    MyCommandColumn.cs
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    using Ext.Net;
    
    namespace Work
    {
        [Meta]
        public class MyCommandColumn : CommandColumn
        {
            public override string Header
            {
                get
                {
                    return "Header";
                }
                set
                {
                    base.Header = value;
                }
            }
    
            public override Unit Width
            {
                get
                {
                    return new Unit(45);
                }
                set
                {
                    base.Width = value;
                }
            }
    
            public override Alignment ButtonAlign
            {
                get
                {
                    return Alignment.Center;
                }
                set
                {
                    base.ButtonAlign = value;
                }
            }
    
            private GridCommandCollection commands;
    
            [Meta]
            [ConfigOption("commands", JsonMode.AlwaysArray)]
            [Category("3. CommandColumn")]
            [NotifyParentProperty(true)]
            [PersistenceMode(PersistenceMode.InnerProperty)]
            [ViewStateMember]
            override public GridCommandCollection Commands
            {
                get
                {
                    if (this.commands == null)
                    {
                        this.commands = new GridCommandCollection()
                        {
                            new GridCommand() 
                            {
                                CommandName = "test",
                                Icon = Icon.Accept,
                                ToolTip = 
                                {
                                    Text = "Tooltip"
                                }
                            }
                        };
                    }
    
                    return this.commands;
                }
            }
        }
    }
  3. #3
    Generally speaking, the best guidelines how to extend controls are the Ext.Net sources.
  4. #4
    Good morning, Daniil,

    What you you mean sources? SVN Sources?

    I cant compile the code you provided.

    Exception: Error 2 'Control.CommandColumn' does not contain a definition for 'commands' and no extension method 'commands' accepting a first argument of type 'Control.CommandColumn' could be found (are you missing a using directive or an assembly reference?) CommandColumn.cs 21 26 Control

    Thanks

      [Meta]
        sealed public class CommandColumn : Ext.Net.CommandColumn
        {
    
            [Meta]
            [ConfigOption("commands", JsonMode.AlwaysArray)]
            [Category("3. CommandColumn")]
            [NotifyParentProperty(true)]
            [PersistenceMode(PersistenceMode.InnerProperty)]
            [ViewStateMember]
            override public GridCommandCollection Commands
            {
                get
                {
                    if (this.commands == null)
                    {
                        this.commands = new GridCommandCollection()
                        {
                            new GridCommand()
                            {
                                CommandName = "test",
                                Icon = Icon.Accept,
                                ToolTip =
                                {
                                    Text = "Tooltip"
                                }
                            }
                        };
                    }
    
                    return this.commands;
                }
            }
  5. #5
    Quote Originally Posted by SouthDeveloper View Post
    Good morning, Daniil,

    What you you mean sources? SVN Sources?
    Well, I mean any Ext.Net sources including the sources fro SVN.


    Quote Originally Posted by SouthDeveloper View Post
    I cant compile the code you provided.

    Exception: Error 2 'Control.CommandColumn' does not contain a definition for 'commands' and no extension method 'commands' accepting a first argument of type 'Control.CommandColumn' could be found (are you missing a using directive or an assembly reference?) CommandColumn.cs 21 26 Control

    Thanks

      [Meta]
        sealed public class CommandColumn : Ext.Net.CommandColumn
        {
    
            [Meta]
            [ConfigOption("commands", JsonMode.AlwaysArray)]
            [Category("3. CommandColumn")]
            [NotifyParentProperty(true)]
            [PersistenceMode(PersistenceMode.InnerProperty)]
            [ViewStateMember]
            override public GridCommandCollection Commands
            {
                get
                {
                    if (this.commands == null)
                    {
                        this.commands = new GridCommandCollection()
                        {
                            new GridCommand()
                            {
                                CommandName = "test",
                                Icon = Icon.Accept,
                                ToolTip =
                                {
                                    Text = "Tooltip"
                                }
                            }
                        };
                    }
    
                    return this.commands;
                }
            }
    There is the following code in the sample that I posted.
    private GridCommandCollection commands;
    I can't see this code in the code you posted.

    Well, just try with exactly the code that I posted.
  6. #6
    I am sorry, Daniil. I missed that line. The code works fine.

    Is it possible to set Header GridCommandCollection Commands ?

    Like this:

            private GridCommandCollection commands;
    
            [Meta]
            [ConfigOption("commands", JsonMode.AlwaysArray)]
            [Category("3. CommandColumn")]
            [NotifyParentProperty(true)]
            [PersistenceMode(PersistenceMode.InnerProperty)]
            [ViewStateMember]
            override public GridCommandCollection Commands
            {
                get
                {
                    if (commands == null)
                    {
                        switch (ColumnStyle)
                        {
                            case ColumnFormat.Update: commands = new GridCommandCollection { new GridCommand { CommandName = "Update", Icon = Icon.Pencil, ToolTip = { Text = "Editar" } } };
                                Header = "Editar";
                                break;
                            case ColumnFormat.Delete: commands = new GridCommandCollection { new GridCommand { CommandName = "Delete", Icon = Icon.Cross, ToolTip = { Text = "Excluir" } } };
                                Header = "Exlcuir";
                                break;
                        }
    
                    }
                    return this.commands;
                }
            }
  7. #7
    I wasnt able to set header from GridCommandColumn. Should I be able?

    I did a workaround. What do you think of it?

    
        [Meta]
        sealed public class CommandColumn : Ext.Net.CommandColumn
        {
            public ColumnFormat ColumnStyle { get; set; }
    
            public enum ColumnFormat
            {
                Update,
                Delete
            }
    
            public override Unit Width
            {
                get
                {
                    return new Unit(45);
                }
                set
                {
                    base.Width = value;
                }
            }
    
            public override string Header
            {
                get
                {
                    switch (ColumnStyle)
                    {
                        case ColumnFormat.Update:
                            return "Editar";
                        case ColumnFormat.Delete:
                            return "Excluir";
                    }
                    return string.Empty;
                }
                set
                {
                    base.Header = value;
                }
            }
    
            private GridCommandCollection commands;
    
            [Meta]
            [ConfigOption("commands", JsonMode.AlwaysArray)]
            [Category("3. CommandColumn")]
            [NotifyParentProperty(true)]
            [PersistenceMode(PersistenceMode.InnerProperty)]
            [ViewStateMember]
            override public GridCommandCollection Commands
            {
                get
                {
                    if (commands == null)
                    {
                        switch (ColumnStyle)
                        {
                            case ColumnFormat.Update: 
                                commands = new GridCommandCollection { new GridCommand { CommandName = "Update", Icon = Icon.Pencil, ToolTip = { Text = "Editar" } } };
                                break;
                            case ColumnFormat.Delete: 
                                commands = new GridCommandCollection { new GridCommand { CommandName = "Delete", Icon = Icon.Cross, ToolTip = { Text = "Excluir" } } };
                                break;
                        }
    
                    }
                    return commands;
                }
            }
    
        }
  8. #8
    Well, you properly set header - overrode .Header property.

    I also overrode .Header property in my example.
  9. #9
    Yep, I copied override from your example.

    Thanks! Please, mark as solved.

Similar Threads

  1. Inherit Coolite ScriptManager
    By kowi in forum 1.x Help
    Replies: 3
    Last Post: Nov 12, 2009, 5:56 PM
  2. Replies: 2
    Last Post: Oct 15, 2009, 12:12 PM
  3. Replies: 1
    Last Post: Feb 24, 2009, 6:13 AM
  4. [CLOSED] Inherit KeyMap
    By Jurke in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jan 15, 2009, 10:59 AM
  5. CommandColumn
    By Rod in forum Feature Requests
    Replies: 7
    Last Post: Oct 27, 2008, 2:17 PM

Posting Permissions