[CLOSED] GridPanel ComboBox Editor Icon

  1. #1

    [CLOSED] GridPanel ComboBox Editor Icon

    Hello,

    I am using custom styles in conjunction with item templates and iconCls to get a ComboBox view I need. I could do what I want with a stand-alone combobox but I have problems with using the same combo box as a grid cell editor.

    Problems are:
    1) When first clicked to edit "Value" column of any row, MyComboEditor.valueModels.length equals zero so I can not set IconCls. Removing the length check causes javascript error.

    2) For the proceeding edit cliks, requirement is almost satisfied but combo box editor value is rendered as if there is no Icon so the text appears behind the colored square I place as combo icon.

    Here is the sample code:

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            string Item1Color = "#FF0000";
            string Item2Color = "#00FF00";
            string Item3Color = "#0000FF";        
            Store store = this.ComboBox1.GetStore();        
            store.DataSource = new object[]
            {
                new object[] { 0, "item1-style", "Item 1", Item1Color},
                new object[] { 1, "item2-style", "Item 2", Item2Color},
                new object[] { 2, "item3-style", "Item 3", Item3Color},
            };        
            store.DataBind();
            System.Web.UI.HtmlControls.HtmlGenericControl mystyles;
            mystyles = new System.Web.UI.HtmlControls.HtmlGenericControl();
            mystyles.TagName = "style";
            mystyles.Attributes.Add("type", "text/css");        
            string ItemStyles = "";
            ItemStyles += ".item1-style {background-repeat   : no-repeat !important;background-position : 3px 50% !important;padding-left: 10px !important;  font-size:10px;padding-left:10px; border:1px solid black;background-color: " + Item1Color + ";overflow:hidden;}";
            ItemStyles += ".item2-style {background-repeat   : no-repeat !important;background-position : 3px 50% !important;padding-left: 10px !important;  font-size:10px;padding-left:10px; border:1px solid black;background-color: " + Item2Color + ";overflow:hidden;}";
            ItemStyles += ".item3-style {background-repeat   : no-repeat !important;background-position : 3px 50% !important;padding-left: 10px !important;  font-size:10px;padding-left:10px; border:1px solid black;background-color: " + Item3Color + ";overflow:hidden;}";
            mystyles.InnerText = ItemStyles;
            Page.Header.Controls.Add(mystyles);
            ComboBox1.Value = "Item 1";
            ComboBox1.IconCls = "item1-style";
    
    
            List<object> MyList = new List<object>();
            for (short i = 0; i < 3; i++)
            {
                MyList.Add(new
                {
                    ID = i,
                    ValueID=i
                });
            }
            this.MyStore.DataSource = MyList;
            this.MyStore.DataBind();             
        }
    </script>
    <script type="text/javascript">
        function myRenderer(value) {
            return "<span class=" + App.Store1.getById(value).data.itemCls + ">&nbsp</span>&nbsp" + App.Store1.getById(value).data.name;
        }
    </script>
    <html>
    <head id="Head1" runat="server">
        <title>IconCombo - Ext.NET Examples</title>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            
            <h1>Render an Icon in ComboBox data items</h1>
    
            <ext:ComboBox ID="ComboBox1" runat="server" Width="400" Editable="false" DisplayField="name" ValueField="ID" LabelWidth="200" FieldLabel="Working stand-alone sample" QueryMode="Local" TriggerAction="All">
                <Store>
                    <ext:Store ID="Store1" runat="server">
                        <Model>
                            <ext:Model ID="Model1" runat="server" IDProperty="ID">
                                <Fields>
                                    <ext:ModelField Name="ID" />
                                    <ext:ModelField Name="itemCls" />
                                    <ext:ModelField Name="name" />
                                    <ext:ModelField Name="ColorCode" />
                                </Fields>
                            </ext:Model>
                        </Model>    
                        <Listeners>
                            <Load Handler="App.MyStore.load()"></Load>
                        </Listeners>        
                    </ext:Store>
                </Store>
                <Listeners>
                    <Change Handler="if (this.valueModels.length > 0) { this.setIconCls(this.store.getById(newValue).data.itemCls); }" />
                </Listeners>  
                <ListConfig>
                    <ItemTpl ID="ItemTpl1" runat="server">
                        <Html>                                                                    
                            <div>
                                <span style="font-size:10px; padding-left:10px; border:1px solid black; background-color:{ColorCode}; overflow:hidden;">&nbsp</span>&nbsp{name}
                            </div>
                        </Html>   
                    </ItemTpl>
                </ListConfig>
            </ext:ComboBox>            
    
            <ext:GridPanel ID="MyGrid" runat="server" MaxHeight="300" Collapsible="false" Flex="1" Title="My Grid" SelectionMemory="false">
                <Store>
                    <ext:Store ID="MyStore" runat="server" AutoLoad="false">
                        <Model>
                            <ext:Model ID="MyStoreModel" runat="server" IDProperty="ID">
                                <Fields>
                                    <ext:ModelField Name="ID" Type="Int"></ext:ModelField>            
                                    <ext:ModelField Name="ValueID" Type="Int"></ext:ModelField>      
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>             
                </Store>
                <ColumnModel runat="server" ID="MyColumnModel">
                    <Columns>                                                                                                                                                            
                        <ext:Column ID="ID" runat="server" Text="ID" DataIndex="ID" Align="Left" Flex="1"/>
                        <ext:Column ID="MyValue" runat="server" Text="Value" DataIndex="ValueID" Align="Left" Flex="1">
                            <Renderer Fn="myRenderer"></Renderer>                       
                            <Editor>
                                <ext:ComboBox runat="server" ID="MyComboEditor" DisplayField="name" ValueField="ID" StoreID="Store1">
                                    <ListConfig>
                                        <ItemTpl ID="ItemTpl2" runat="server">
                                            <Html>                                                                    
                                                <div>
                                                    <span style="font-size:10px; padding-left:10px; border:1px solid black; background-color:{ColorCode}; overflow:hidden;">&nbsp</span>&nbsp{name}
                                                </div>
                                            </Html>   
                                        </ItemTpl>
                                    </ListConfig>
                                    <Listeners>
                                        <Change Handler="if (this.valueModels.length > 0) { this.setIconCls(this.store.getById(newValue).data.itemCls); }"></Change>
                                    </Listeners>                             
                                </ext:ComboBox>
                            </Editor>
                        </ext:Column>   
                    </Columns>
                </ColumnModel>   
                <Plugins>
                    <ext:CellEditing ID="CellEditing1" runat="server">
                        <Listeners>
                            <BeforeEdit Handler="if (App.MyComboEditor.valueModels.length > 0) { App.MyComboEditor.setIconCls(App.Store1.getById(e.value).data.itemCls);}"></BeforeEdit>
                        </Listeners>
                    </ext:CellEditing>
                </Plugins> 
            </ext:GridPanel>
        </form>
    </body>
    </html>
    Thanks.
    Last edited by Daniil; Mar 20, 2013 at 2:11 PM. Reason: [CLOSED]
  2. #2
    Hello!

    Try to use this one:

    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <!DOCTYPE html>
     
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            string Item1Color = "#FF0000";
            string Item2Color = "#00FF00";
            string Item3Color = "#0000FF";        
            Store store = this.ComboBox1.GetStore();        
            store.DataSource = new object[]
            {
                new object[] { 0, "item1-style", "Item 1", Item1Color},
                new object[] { 1, "item2-style", "Item 2", Item2Color},
                new object[] { 2, "item3-style", "Item 3", Item3Color},
            };        
            store.DataBind();
            System.Web.UI.HtmlControls.HtmlGenericControl mystyles;
            mystyles = new System.Web.UI.HtmlControls.HtmlGenericControl();
            mystyles.TagName = "style";
            mystyles.Attributes.Add("type", "text/css");        
            string ItemStyles = "";
            ItemStyles += ".item1-style {background-repeat   : no-repeat !important;background-position : 3px 50% !important;padding-left: 10px !important;  font-size:10px;padding-left:10px; border:1px solid black;background-color: " + Item1Color + ";overflow:hidden;}";
            ItemStyles += ".item2-style {background-repeat   : no-repeat !important;background-position : 3px 50% !important;padding-left: 10px !important;  font-size:10px;padding-left:10px; border:1px solid black;background-color: " + Item2Color + ";overflow:hidden;}";
            ItemStyles += ".item3-style {background-repeat   : no-repeat !important;background-position : 3px 50% !important;padding-left: 10px !important;  font-size:10px;padding-left:10px; border:1px solid black;background-color: " + Item3Color + ";overflow:hidden;}";
            mystyles.InnerText = ItemStyles;
            Page.Header.Controls.Add(mystyles);
            ComboBox1.Value = "Item 1";
            ComboBox1.IconCls = "item1-style";
     
     
            List<object> MyList = new List<object>();
            for (short i = 0; i < 3; i++)
            {
                MyList.Add(new
                {
                    ID = i,
                    ValueID=i
                });
            }
            this.MyStore.DataSource = MyList;
            this.MyStore.DataBind();             
        }
    </script>
    <script type="text/javascript">
        function myRenderer(value) {
            return "<span class=" + App.Store1.getById(value).data.itemCls + ">&nbsp</span>&nbsp" + App.Store1.getById(value).data.name;
        }
    </script>
    <html>
    <head id="Head1" runat="server">
        <title>IconCombo - Ext.NET Examples</title>
        
        <style>
            .ux-icon-combo-editor input.x-form-field {
                padding-left: 20px;
            }
        </style>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
             
            <h1>Render an Icon in ComboBox data items</h1>
     
            <ext:ComboBox ID="ComboBox1" runat="server" Width="400" Editable="false" DisplayField="name" ValueField="ID" LabelWidth="200" FieldLabel="Working stand-alone sample" QueryMode="Local" TriggerAction="All">
                <Store>
                    <ext:Store ID="Store1" runat="server">
                        <Model>
                            <ext:Model ID="Model1" runat="server" IDProperty="ID">
                                <Fields>
                                    <ext:ModelField Name="ID" />
                                    <ext:ModelField Name="itemCls" />
                                    <ext:ModelField Name="name" />
                                    <ext:ModelField Name="ColorCode" />
                                </Fields>
                            </ext:Model>
                        </Model>    
                        <Listeners>
                            <Load Handler="App.MyStore.load()"></Load>
                        </Listeners>        
                    </ext:Store>
                </Store>
                <Listeners>
                    <Change Handler="this.setIconCls(this.store.getById(newValue).data.itemCls);" />
                </Listeners>  
                <ListConfig>
                    <ItemTpl ID="ItemTpl1" runat="server">
                        <Html>                                                                    
                            <div>
                                <span style="font-size:10px; padding-left:10px; border:1px solid black; background-color:{ColorCode}; overflow:hidden;">&nbsp</span>&nbsp{name}
                            </div>
                        </Html>   
                    </ItemTpl>
                </ListConfig>
            </ext:ComboBox>            
     
            <ext:GridPanel ID="MyGrid" runat="server" MaxHeight="300" Collapsible="false" Flex="1" Title="My Grid" SelectionMemory="false">
                <Store>
                    <ext:Store ID="MyStore" runat="server" AutoLoad="false">
                        <Model>
                            <ext:Model ID="MyStoreModel" runat="server" IDProperty="ID">
                                <Fields>
                                    <ext:ModelField Name="ID" Type="Int"></ext:ModelField>            
                                    <ext:ModelField Name="ValueID" Type="Int"></ext:ModelField>      
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>             
                </Store>
                <ColumnModel runat="server" ID="MyColumnModel">
                    <Columns>                                                                                                                                                            
                        <ext:Column ID="ID" runat="server" Text="ID" DataIndex="ID" Align="Left" Flex="1"/>
                        <ext:Column ID="MyValue" runat="server" Text="Value" DataIndex="ValueID" Align="Left" Flex="1">
                            <Renderer Fn="myRenderer"></Renderer>                       
                            <Editor>
                                <ext:ComboBox runat="server" ID="MyComboEditor" DisplayField="name" ValueField="ID" StoreID="Store1" Cls="ux-icon-combo-editor">
                                    <ListConfig>
                                        <ItemTpl ID="ItemTpl2" runat="server">
                                            <Html>                                                                    
                                                <div>
                                                    <span style="font-size:10px; padding-left:10px; border:1px solid black; background-color:{ColorCode}; overflow:hidden;">&nbsp</span>&nbsp{name}
                                                </div>
                                            </Html>   
                                        </ItemTpl>
                                    </ListConfig>
                                    <Listeners>
                                        <Change Handler="if (this.valueModels.length > 0) { this.setIconCls(this.store.getById(newValue).data.itemCls); }"></Change>
                                    </Listeners>                             
                                </ext:ComboBox>
                            </Editor>
                        </ext:Column>   
                    </Columns>
                </ColumnModel>   
                <Plugins>
                    <ext:CellEditing ID="CellEditing1" runat="server">
                        <Listeners>
                            <BeforeEdit Handler="
                            if (App.MyComboEditor.rendered)
                                App.MyComboEditor.setIconCls(App.Store1.getById(e.value).data.itemCls);
                            else {
                                App.MyComboEditor.on('render', function() { 
                                    this.setIconCls(App.Store1.getById(e.value).data.itemCls);
                                });
                            }
                            "></BeforeEdit>
                        </Listeners>
                    </ext:CellEditing>
                </Plugins> 
            </ext:GridPanel>
        </form>
    </body>
    </html>
  3. #3
    Hi,

    Thanks for the code. Issue #2 continues for IE9. ux-icon-combo-editor's padding-left is working with Chrome but the text still appears behind the icon in IE9.
  4. #4
    Hello,

    Please make the rule stronger using an "!important" statement.
    .ux-icon-combo-editor input.x-form-field {
        padding-left: 20px !important;
    }
    By the way, using the IE Developer Tools to inspect HTML elements and its CSS rules helps much to fix such issues.
  5. #5
    Quote Originally Posted by Daniil View Post
    Hello,

    Please make the rule stronger using an "!important" statement.
    .ux-icon-combo-editor input.x-form-field {
        padding-left: 20px !important;
    }
    By the way, using the IE Developer Tools to inspect HTML elements and its CSS rules helps much to fix such issues.
    You are right, thank you Daniil.
    Please mark as closed.

Similar Threads

  1. [CLOSED] Combobox in Gridpanel editor plugin
    By CarWise in forum 1.x Legacy Premium Help
    Replies: 16
    Last Post: May 07, 2012, 3:59 PM
  2. Replies: 2
    Last Post: May 05, 2011, 10:16 AM
  3. Replies: 5
    Last Post: Mar 05, 2010, 3:15 PM
  4. ComboBox Editor inside GridPanel
    By jsemple in forum 1.x Help
    Replies: 1
    Last Post: Feb 27, 2009, 11:58 AM
  5. Replies: 2
    Last Post: Feb 24, 2009, 5:45 PM

Posting Permissions