[CLOSED] store.filter method is not working

  1. #1

    [CLOSED] store.filter method is not working

    Hello,
    I am trying to use the "filter" method to filter out my Store's data. The code I am using is:
     App.stLocation.filter('Divname', new RegExp('^' + value + '$'));
    Can you please tell me what I am doing wrong? Thank you very much.
    Below is my entire code:

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <script type="text/javascript">
        // *********************************** Product Filtering ***********************************
        var keyUpProductHandler = function (field, e) {
            var value = field.getValue();
             App.stLocation.filter('Divname', new RegExp('^' + value + '$'));
        }
    
    </script>
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                this.stLocation.DataSource = new object[]
                {
                    new object[] { "12345 - 3m Co", 12345},
                    new object[] { "29345 - Alcoa Inc",29345},
                    new object[] { "28345 - Altria Group Inc", 28345 },
                    new object[] { "American Express Company", 27345 },
                    new object[] { "American International Group, Inc.", 26345},
                    new object[] { "AT&T Inc.", 312345},
                    new object[] { "Boeing Co.", 25345},
                    new object[] { "Caterpillar Inc.", 24345 },
                    new object[] { "Citigroup, Inc.", 232345},
                    new object[] { "E.I. du Pont de Nemours and Company", 222345},
                    new object[] { "Exxon Mobil Corp", 212345 },
                    new object[] { "General Electric Company", 192345},
                    new object[] { "General Motors Corporation", 182345 },
                    new object[] { "Hewlett-Packard Co.", 172345 },
                    new object[] { "Honeywell Intl Inc", 162345},
                    new object[] { "Intel Corporation", 152345 },
                    new object[] { "International Business Machines", 142345 },
                    new object[] { "Johnson & Johnson", 132345},
                    new object[] { "JP Morgan & Chase & Co", 12345 },
                    new object[] { "McDonald\"s Corporation", 112345 },
                    new object[] { "Merck & Co., Inc.", 102345 },
                    new object[] { "Microsoft Corporation", 92345 },
                    new object[] { "Pfizer Inc", 82345 },
                    new object[] { "The Coca-Cola Company", 72345},
                    new object[] { "The Home Depot, Inc.", 62345},
                    new object[] { "The Procter & Gamble Company", 52345 },
                    new object[] { "United Technologies Corporation",42345 },
                    new object[] { "Verizon Communications", 32345 },
                    new object[] { "Wal-Mart Stores, Inc.", 22345 }
                };
    
                this.stLocation.DataBind();
            }
        }
    </script>
    <!DOCTYPE html>
    <html>
    <head id="Head1" runat="server">
        <title>Store Filter</title>
    </head>
    <body>
        <form id="Form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:Panel runat="server" Title="Store Filter test">
            <TopBar>
                <ext:Toolbar ID="Toolbar1" runat="server">
                    <Items>
                        <ext:ToolbarTextItem ID="ToolbarTextItem1" runat="server" Text="Find:" />
                        <ext:TriggerField ID="productFilterField" runat="server" EnableKeyEvents="true">
                            <Triggers>
                                <ext:FieldTrigger Icon="Clear" Qtip="Clear filter" />
                            </Triggers>
                            <Listeners>
                                <KeyUp Fn="keyUpProductHandler" />
                             
                            </Listeners>
                        </ext:TriggerField>
                    </Items>
                </ext:Toolbar>
            </TopBar>
            <Items>
                  <ext:Container ID="conLocation" runat="server">
                    <Items>
                        <ext:MultiSelect ID="lstProducts" runat="server" Height="130" DisplayField="Divname"
                            ValueField="LocationKey" AutoDataBind="true" Width="300">
                            <Store>
                                <ext:Store ID="stLocation" runat="server">
                                    <Model>
                                        <ext:Model ID="mdLocation" runat="server">
                                            <Fields>
                                                <ext:ModelField Name="Divname" Type="String" />
                                                <ext:ModelField Name="LocationKey" Type="String" />
                                            </Fields>
                                        </ext:Model>
                                    </Model>
                                </ext:Store>
                            </Store>
                        </ext:MultiSelect>
                    </Items>
                </ext:Container>
            </Items>
        </ext:Panel>
        </form>
    </body>
    </html>
    Last edited by Baidaly; Jul 01, 2013 at 8:25 PM. Reason: [CLOSED]
  2. #2
    Hello!

    Sorry, I don't quite understand your requirements. Can you provide more details about requirements? However, to filter the store, you should use something like this:

    var keyUpProductHandler = function (field, e) {
    	var value = field.getValue();
    	
    	if (value.length > 0) {
    		App.stLocation.clearFilter();
    		App.stLocation.filter('Divname', new RegExp('\^' + value + '$'));
    	}  else
    		App.stLocation.clearFilter();
    }
  3. #3
    OK. Here are some more information on what I am trying to accomplish.

    I have a TriggerField for users to type in a text. As the users type in the TriggerField, the search results should be filtered and then displayed in the MultiSelect control. In my example, if the user types "a" in the TriggerField, the Store should filter and return only two items which are "Caterpillar Inc." and "Ciitgroup, Inc."

    I tried you suggestion below and it didn't for me. It just clears the TriggerField.


    Quote Originally Posted by Baidaly View Post
    Hello!

    Sorry, I don't quite understand your requirements. Can you provide more details about requirements? However, to filter the store, you should use something like this:

    var keyUpProductHandler = function (field, e) {
    	var value = field.getValue();
    	
    	if (value.length > 0) {
    		App.stLocation.clearFilter();
    		App.stLocation.filter('Divname', new RegExp('\^' + value + '$'));
    	}  else
    		App.stLocation.clearFilter();
    }
  4. #4
    Quote Originally Posted by Fahd View Post
    OK. Here are some more information on what I am trying to accomplish.

    I have a TriggerField for users to type in a text. As the users type in the TriggerField, the search results should be filtered and then displayed in the MultiSelect control. In my example, if the user types "a" in the TriggerField, the Store should filter and return only two items which are "Caterpillar Inc." and "Ciitgroup, Inc."

    I tried you suggestion below and it didn't for me. It just clears the TriggerField.
    Sorry, my question was about the logic of store filtration.

    If users type 'a' then you return "Caterpillar Inc." and "Ciitgroup, Inc.". Why do you return this two objects? There is no 'a' in "Ciitgroup, Inc.".

    You can check you RegEx using this tool: http://regexpal.com/

    And then send to filter function:

    App.stLocation.filter('Divname', new RegExp('\^' + value + '$'));
  5. #5
    sorry for the typo. I meant to say " if the user types a "c" in the TriggerField, the Store should filter and return only two items which are "Caterpillar Inc." and "Ciitgroup, Inc." " and what I am trying to do is narrow down the Store's data as users type in the TriggerField so that they do not have to see so much data at a given time.


    Quote Originally Posted by Baidaly View Post
    Sorry, my question was about the logic of store filtration.

    If users type 'a' then you return "Caterpillar Inc." and "Ciitgroup, Inc.". Why do you return this two objects? There is no 'a' in "Ciitgroup, Inc.".

    You can check you RegEx using this tool: http://regexpal.com/

    And then send to filter function:

    App.stLocation.filter('Divname', new RegExp('\^' + value + '$'));
  6. #6
    Try this one:

    var keyUpProductHandler = function (field, e) {
        var value = field.getValue();
    
        if (value.length > 0) {
            App.stLocation.clearFilter();
            App.stLocation.filter('Divname', new RegExp('\^' + value + ".*", "i"));
        } else
            App.stLocation.clearFilter();
    }
  7. #7
    Thank you for your help! Your code works fine in my example. I just had to change the Regular Expression a little to also make it search any where in a string like this:
    App.StoreLocation.filter('Divname', new RegExp(value + ".*", "i"));

    Quote Originally Posted by Baidaly View Post
    Try this one:

    var keyUpProductHandler = function (field, e) {
        var value = field.getValue();
    
        if (value.length > 0) {
            App.stLocation.clearFilter();
            App.stLocation.filter('Divname', new RegExp('\^' + value + ".*", "i"));
        } else
            App.stLocation.clearFilter();
    }

Similar Threads

  1. Replies: 3
    Last Post: Nov 05, 2013, 9:34 AM
  2. [CLOSED] store.insert method + store page size problem
    By mcfromero in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 12, 2012, 6:34 AM
  3. [CLOSED] Direct Method only working once
    By CarWise in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jan 07, 2011, 9:09 AM
  4. [CLOSED] CheckboxSelectionModel is not working when using filter
    By russ in forum 1.x Legacy Premium Help
    Replies: 11
    Last Post: Jan 05, 2011, 9:57 AM
  5. File download not working in ajax method...
    By speedstepmem2 in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jan 08, 2009, 5:28 AM

Tags for this Thread

Posting Permissions