[CLOSED] Combobox search without using template

  1. #1

    [CLOSED] Combobox search without using template

    Hi,

    what is best way to add search to a standard combobox - I've just one displayfield...nothing complicated like in following example

    https://examples1.ext.net/#/Form/Com...Custom_Search/

    Here is code for combobox I'm using...

    <ext:ComboBox ID="cmbArea" runat="server" FieldLabel="Area" StoreID="storeArea" Width="200"
                                                DisplayField="Name" ValueField="ID" LoadingText="Searching..." HideTrigger="false"
                                                MinChars="1" ReadOnly="true" EmptyText="Select an Area ">
                                            </ext:ComboBox>
    the reason I'm not using template is that the combox text font looks different than other boxes!

    Any help?
    Last edited by Daniil; Nov 08, 2010 at 6:21 AM. Reason: [CLOSED]
  2. #2
    Hi,

    Here is one of examples from this thread.
    http://forums.ext.net/showthread.php...om-search-help

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Import Namespace="System.Linq" %>
     
    <script runat="server">
        private object[] MyData =
            new object[]
            {
                new object[] { "a" },
                new object[] { "b" },
                new object[] { "c" },
                new object[] { "a1" },
                new object[] { "b1" },
                new object[] { "c1" }
            };
     
        [DirectMethod]
        public void GetData(string filter)
        {
            Store store = this.ComboBox1.GetStore();
            if (string.IsNullOrEmpty(filter))
            {
                return;
            }
            else if (filter.Equals("*"))
            {
                store.DataSource = MyData;
            }
            else
            {
                store.DataSource = from x in MyData
                               where (x as object[])[0].ToString().StartsWith(filter)
                               select x;
            }
            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:ComboBox 
            ID="ComboBox1" 
            runat="server" 
            DisplayField="test" 
            ValueField="test"
            TypeAhead="false" 
            HideTrigger="true" 
            EnableKeyEvents="true">
            <Store>
                <ext:Store runat="server" AutoLoad="false">
                    <Reader>
                        <ext:ArrayReader>
                            <Fields>
                                <ext:RecordField Name="test" />
                            </Fields>
                        </ext:ArrayReader>
                    </Reader>
                </ext:Store>
            </Store>
            <Listeners>
                <KeyUp Handler="Ext.net.DirectMethods.GetData(this.getRawValue());" />
            </Listeners>
        </ext:ComboBox>
        </form>
    </body>
    </html>
  3. #3
    Thanks but I'm using v 0.8.2 of coolite, will this example work?

    just to share the mine code, I'm not sure about codebehind

        <ext:ComboBox ID="cmbUnit" runat="server" FieldLabel="Unit" StoreID="storeUnit" Width="200"
                                                DisplayField="Name" ValueField="ID" LoadingText="Searching..." HideTrigger="false"
                                                MinChars="1" ReadOnly="true" EmptyText="Select a unit ">
                                                <Listeners>
                                                    <KeyUp Handler="Coolite.AjaxMethods.GetUnits(this.getRawValue());" />
                                                </Listeners>
                                            </ext:ComboBox>
    
            [AjaxMethod]
            public void GetUnits(string filter)
            {
                DataTable units = new DataTable();
                units = GetAllUnits();
    
                if (filter.Equals("*"))
                {
                    this.storeUnit.DataSource = units 
                }
                else
                {
                    this.storeUnit.DataSource = from x in units where (x as DataTable).Rows[0].ItemArray[0].ToString().StartsWith(filter) select x;
                }
                this.storeUnit.DataBind();
            }

    I think query pattern can't be applied on datatable
  4. #4
    Hi,

    Here is the same example for 0.8.X toolkit's version.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Import Namespace="System.Linq" %>
    
    <script runat="server">
        private object[] MyData =
            new object[]
            {
                new object[] { "a" },
                new object[] { "b" },
                new object[] { "c" },
                new object[] { "a1" },
                new object[] { "b1" },
                new object[] { "c1" }
            };
    
        [AjaxMethod]
        public void GetData(string filter)
        {
            Store store = this.Store1;
            if (string.IsNullOrEmpty(filter))
            {
                return;
            }
            else if (filter.Equals("*"))
            {
                store.DataSource = MyData;
            }
            else
            {
                store.DataSource = from x in MyData
                                   where (x as object[])[0].ToString().StartsWith(filter)
                                   select x;
            }
            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:ScriptManager runat="server" />
        <ext:Store ID="Store1" runat="server" AutoLoad="false">
            <Reader>
                <ext:ArrayReader>
                    <Fields>
                        <ext:RecordField Name="test" />
                    </Fields>
                </ext:ArrayReader>
            </Reader>
        </ext:Store>
        <ext:ComboBox 
            runat="server" 
            StoreID="Store1" 
            DisplayField="test" 
            ValueField="test"
            TypeAhead="false" 
            HideTrigger="true" 
            EnableKeyEvents="true">
            <Listeners>
                <KeyUp Handler="Coolite.AjaxMethods.GetData(this.getRawValue());" />
            </Listeners>
        </ext:ComboBox>
        </form>
    </body>
    </html>
  5. #5
    Quote Originally Posted by sadaf View Post
    I think query pattern can't be applied on datatable
    I'm not sure.

    All the same the goal is to retrieve from an object (DataTable) all data that satisfy the filter's condition. I mean it's unnecessary to use LINQ. You could achieve this by any acceptable way.

Similar Threads

  1. [CLOSED] [1.1] Template Combobox typeahead value select the first row
    By ddslogistics in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Sep 28, 2011, 2:00 PM
  2. [CLOSED] Using custom template in a ComboBox
    By mattwoberts in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 28, 2011, 3:06 PM
  3. [CLOSED] [1.0] ComboBox Template
    By state in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 25, 2010, 5:36 PM
  4. [CLOSED] ComboBox Template for Selected Value
    By Steve in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jun 22, 2009, 10:34 AM
  5. Replies: 1
    Last Post: Oct 29, 2008, 4:44 AM

Posting Permissions