13 Replies Latest reply on May 21, 2007 7:13 PM by shaungish

    filterfunction weirdness

    shaungish Level 1
      I'm using the following code to dynamically filter a datagrid:

      private function filterLastName():void
      {
      customers.filterFunction = searchLastName;
      customers.refresh();
      }

      private function searchLastName(item:Object):Boolean
      {
      var isMatch:Boolean = false;
      if(item.last.toLowerCase().search(search.text.toLowerCase()) != -1)
      {
      isMatch = true;
      }
      return isMatch;
      }

      private function clearSearch():void{
      customers.filterFunction = null;
      customers.refresh();
      search.text = '';
      }

      Then I have a text input field and a button:

      <mx:TextInput id="search" change="filterLastName()" x="79" y="8"/>
      <mx:Button x="366" y="8" label="Clear Search" click="clearSearch()"/>

      Anytime try to use the same code to filter for a phone number (I replace the item.last with item.home) I get an Error 1006 function not found... It seems to happen with numbers... I can change everything to filter out first names or even dates, but anytime I have a number it throws the error... Any ideas?
        • 1. Re: filterfunction weirdness
          BLXWebMaster Level 1
          Is it possible your Tel number needs to be cast as a string? Also, do you have a value in every field? I have seen issues where the field might containt a null and had to change my filter function to nto check nulls. This is a filter I use on Phone Numbers.

          (search.text == '' || (item.work_phone != null && item.work_phone.toString().indexOf(search.text) >= 0))
          • 2. Re: filterfunction weirdness
            shaungish Level 1
            I'll try formatting the tel number as a string...

            Dumb question but how would the datagrid know whether or not the info in that column was a string or not? It's coming from a php script that pulls the info from a mysql database and then echos an string of xml

            Here's the actual code for the php script:

            $customerInfo = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r<customers>\r";
            while($row = mysql_fetch_object($result))
            {
            $customerInfo .= "\t<person>\r
            \t\t<first>".$row->first."</first>\r
            \t\t<middle>".$row->middle."</middle>\r
            \t\t<last>".$row->last."</last>\r
            \t\t<street>".$row->street."</street>\r
            \t\t<city>".$row->city."</city>\r
            \t\t<state>".$row->state."</state>\r
            \t\t<zip>".$row->zip."</zip>\r
            \t\t<home>".$row->home."</home>\r
            \t\t<work>".$row->work."</work>\r
            \t\t<cell>".$row->cell."</cell>\r
            \t\t<email>".$row->email."</email>\r
            \t\t<website>".$row->website."</website>\r
            \t</person>\r";
            }
            $customerInfo .= '</customers>';
            echo $customerInfo;
            • 3. filterfunction weirdness
              BLXWebMaster Level 1
              Good Question, I figured you were pulling query directly from DB. Flex does do some ype checking at run time. I am not exactly sure how this affects values that are not explictly typed.

              I did a quick test using your code with a field called home that contains numbers and I did not have any issues.
              Might want to check the data you are returing and make sure there is nothing goofy with it.

              How about posting entire code and I will take a look.
              • 4. Re: filterfunction weirdness
                shaungish Level 1
                Here's everything... I also posted the compiled version at http://twigs-floral.com/TwigsCMS/bin/TwigsCMS.html

                And actually the filter isn't working correctly at all now... if you go to the view orders page it works, but the filter for the last name doesn't

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
                <mx:Script>
                <![CDATA[
                import mx.rpc.events.FaultEvent;
                import mx.collections.ArrayCollection;
                import mx.rpc.events.ResultEvent;
                import mx.effects.easing.*;
                [Bindable]
                private var customers:ArrayCollection = new ArrayCollection;
                [Bindable]
                private var orders:ArrayCollection = new ArrayCollection;
                [Bindable]
                private var stateNames:ArrayCollection = new ArrayCollection;
                public function handleResult(event:ResultEvent):void {
                newCustomerAdded.text = "Customer Added Succesfully!\n " + String(event.result);
                first.text='';
                middle.text='';
                last.text='';
                street.text='';
                city.text='';
                state.text='';
                zip.text='';
                home.text='';
                work.text='';
                email.text='';
                }
                public function handleFault(event:FaultEvent):void {
                newCustomerAdded.text = "Fault Response from HTTPService call:\n " + event.fault.toString();
                }


                private function customersRPCResult(event:ResultEvent):void
                {
                customers=event.result.customers.person;
                }

                private function ordersRPCResult(event:ResultEvent):void
                {
                orders=event.result.orders.order;
                }

                private function statesRPCResult(event:ResultEvent):void
                {
                stateNames=event.result.usa.state;
                }

                public function changeHandler(event:Event):void
                {
                //this changeHandler is used to populate the orderDetail state
                //change currentState to orderDetail
                currentState = 'orderDetail';
                //change all of the items in orderDetail state - data comes from script/orders.php - php script echos XML
                orderDetail.title = "Viewing Order #"+event.target.selectedItem.orderID;
                dateIn.text = event.target.selectedItem.dateIn;
                status.text = event.target.selectedItem.status;
                occasion.text = event.target.selectedItem.occasion;
                cardInfo.text = event.target.selectedItem.cardInfo;
                description.text = event.target.selectedItem.description;
                notes.text = event.target.selectedItem.notes;
                dueConcat.text = event.target.selectedItem.deliveryDate +" "+ event.target.selectedItem.deliveryTime +" "+ event.target.selectedItem.meridiem;
                //temporary customer info
                toCustomer.text = event.target.selectedItem.rid;
                fromCustomer.text = event.target.selectedItem.cid;
                //change colors of text for the status message to alert user
                if (status.text == 'alert'){
                status.setStyle("color", 0xff0000);
                }
                if (status.text == 'pending'){
                status.setStyle("color", 0xcc9900);
                }
                if (status.text == 'delivering'){
                status.setStyle("color", 0x339900);
                }
                }


                private function orderSearch():void
                {
                orders.filterFunction = searchOrders;
                orders.refresh();
                }

                private function searchOrders(item:Object):Boolean
                {
                var isMatch2:Boolean = false;
                if(item.status.toLowerCase().search(orderSearchInput.text.toLowerCase()) != -1)
                {
                isMatch2 = true;
                }
                return isMatch2;
                }

                private function filterLastName():void
                {
                customers.filterFunction = searchLastName;
                customers.refresh();
                }

                private function searchLastName(item:Object):Boolean
                {
                var isMatch2:Boolean = false;
                if(item.last.toLowerCase().search(nameSearchInput.text.toLowerCase()) != -1)
                {
                isMatch2 = true;
                }
                return isMatch2;
                }




                private function clearSearch():void{
                customers.filterFunction = null;
                customers.refresh();
                nameSearchInput.text = '';
                }

                ]]>
                </mx:Script>

                <mx:Dissolve id="myDissolve" duration="300" />
                <!--connect to states.xml to populate a combo box-->
                <mx:HTTPService id="statesRPC" url="assets/states.xml" result="statesRPCResult(event)"/>
                <!--connect to customer info php script - generates xml-->
                <mx:HTTPService id="customersRPC" url="scripts/customers.php" result="customersRPCResult(event)"/>
                <!--connect to order info php script - generates xml-->
                <mx:HTTPService id="ordersRPC" url="scripts/orders.php" result="ordersRPCResult(event)"/>
                <!--pass info to create new user via POST-->
                <mx:HTTPService id="newCustomerForm" url="scripts/addcustomer.php" method="POST" result="handleResult(event)" fault="handleFault(event)" resultFormat="text">
                <mx:request>
                <first>{first.text}</first>
                <middle>{middle.text}</middle>
                <last>{last.text}</last>
                <street>{street.text}</street>
                <city>{city.text}</city>
                <state>{state.text}</state>
                <zip>{zip.text}</zip>
                <home>{home.text}</home>
                <work>{work.text}</work>
                <email>{email.text}</email>
                </mx:request>
                </mx:HTTPService>
                <!--transitions-->
                <mx:transitions>
                <!--Play to go from ANY state to initial login state-->
                <mx:Transition id="toLoginFromAny" fromState="*" toState="start">
                <mx:Resize target="{panel1}"/>
                </mx:Transition>

                <!--Play to go from initial login state to overview main state-->
                <mx:Transition id="loginToMain" fromState="" toState="main">
                <mx:Parallel>
                <mx:Resize target="{panel1}" easingFunction="Exponential.easeInOut" duration="300" />
                </mx:Parallel>
                </mx:Transition>

                <mx:Transition fromState="main" toState="allOrders">
                <mx:Sequence>
                <mx:Dissolve target="{allOrders}" duration="300"/>
                </mx:Sequence>
                </mx:Transition>

                <mx:Transition fromState="*" toState="main" >
                <mx:Parallel targets="{[linkbar1, mainWindow, panel3, panel2]}" >
                <mx:Dissolve duration="300" alphaFrom="0.0" alphaTo="1.0"/>
                </mx:Parallel>
                </mx:Transition>

                <mx:Transition fromState="allOrders" toState="orderDetail">
                <mx:Parallel>
                • 5. Re: filterfunction weirdness
                  shaungish Level 1
                  <mx:Resize target="{allOrders}" duration="300"/>
                  <mx:Move target="{orderDetail}" yFrom="580" duration="600"/>

                  </mx:Parallel>
                  </mx:Transition>
                  </mx:transitions>
                  <mx:states>
                  <mx:State name="main">
                  <mx:RemoveChild target="{twigsLogo}"/>
                  <mx:RemoveChild target="{username}"/>
                  <mx:RemoveChild target="{label1}"/>
                  <mx:RemoveChild target="{password}"/>
                  <mx:RemoveChild target="{label2}"/>
                  <mx:RemoveChild target="{login}"/>
                  <mx:SetProperty target="{panel1}" name="width" value="711"/>
                  <mx:SetProperty target="{panel1}" name="height" value="530"/>
                  <mx:SetProperty target="{panel1}" name="title">
                  <mx:value>Welcome to Twig Floral's Customer Management System</mx:value>
                  </mx:SetProperty>
                  <mx:AddChild relativeTo="{panel1}" position="lastChild">
                  <mx:Panel x="10" y="10" width="170" height="470" layout="absolute" title="Pending Orders" id="panel2" showEffect="Fade">
                  <mx:List x="0" y="0" width="150" height="430" id="recent" dataProvider="{orders}" labelField="orderID" creationComplete="ordersRPC.send()"/>
                  </mx:Panel>
                  </mx:AddChild>
                  <mx:AddChild relativeTo="{panel1}" position="lastChild">
                  <mx:Panel x="188" y="280" width="493" height="200" layout="absolute" title="Customer Search" id="panel3">
                  <mx:DataGrid x="10" y="36" width="453" id="customerInfo" height="114" dataProvider="{customers}" creationComplete="customersRPC.send()">
                  <mx:columns>
                  <mx:DataGridColumn headerText="Last Name" dataField="last"/>
                  <mx:DataGridColumn headerText="First Name" dataField="first"/>
                  <mx:DataGridColumn headerText="Phone Number" dataField="home"/>
                  </mx:columns>
                  </mx:DataGrid>
                  <mx:Label x="10" y="10" text="last name" textAlign="right"/>
                  <mx:TextInput id="nameSearchInput" change="filterLastName()" x="79" y="8"/>
                  <mx:Button x="247" y="8" label="Clear Search" click="clearSearch()"/>
                  <mx:Button x="369" y="8" label="Refresh List" />
                  </mx:Panel>
                  </mx:AddChild>
                  <mx:AddChild relativeTo="{panel1}" position="lastChild">
                  <mx:ViewStack x="188" y="40" id="mainWindow" width="493" height="232">
                  <mx:Panel id="overview" label="Overview" width="100%" height="100%" title="Overview" layout="absolute" showEffect="{myDissolve}">
                  </mx:Panel>
                  <mx:Panel id="newCustomer" label="New Customer" width="100%" height="100%" title="Add a New Customer" layout="absolute" showEffect="{myDissolve}">
                  <mx:Label text="Customer Name" x="10" y="12" textAlign="right"/>
                  <mx:TextInput x="113" y="10" width="117" id="first"/>
                  <mx:TextInput x="238" y="10" width="103" id="middle"/>
                  <mx:TextInput x="349" y="10" width="114" id="last"/>

                  <mx:Label text="Street Address" x="19" y="40" textAlign="right"/>
                  <mx:TextInput x="113" y="38" width="350" id="street"/>

                  <mx:Label text="City" x="79" y="68" textAlign="right" height="20"/>
                  <mx:TextInput x="113" y="66" width="139" id="city"/>

                  <mx:Label text="State" x="260" y="68" textAlign="right" height="20"/>
                  <mx:ComboBox x="302" y="66" width="67" id="state" dataProvider="{stateNames}" creationComplete="statesRPC.send()">

                  </mx:ComboBox>

                  <mx:Label text="Zip" x="377" y="68" textAlign="right" height="20"/>
                  <mx:TextInput x="402" y="66" width="61" id="zip"/>

                  <mx:Label text="Home Phone" x="28" y="98" textAlign="right" height="20"/>
                  <mx:TextInput x="113" y="96" width="139" id="home"/>

                  <mx:Label text="Work Phone" x="32" y="128" textAlign="right" height="20"/>
                  <mx:TextInput x="113" y="126" width="139" id="work"/>

                  <mx:Label text="Email Address" x="22" y="158" textAlign="right" height="20"/>
                  <mx:TextInput x="113" y="156" width="139" id="email"/>

                  <mx:Button x="329" y="156" label="Add New Customer" click="newCustomerForm.send()"/>
                  <mx:TextArea x="260" y="97" width="203" height="51" id="newCustomerAdded" fontWeight="bold" color="#008040" fontSize="12" borderStyle="none" textAlign="center" editable="false"/>
                  </mx:Panel>
                  <mx:Panel id="newOrder" label="New Order" width="100%" height="100%" title="Add a New Order" layout="absolute" showEffect="{myDissolve}">
                  <mx:Button x="10" y="10" label="New Customer" id="button2"/>
                  <mx:Button x="10" y="40" label="Returning Customer" id="button1" click="currentState='returnCustomerNew'"/>
                  </mx:Panel>
                  <mx:Panel id="viewOrders" label="View Orders" width="100%" height="100%" title="View All Orders" layout="absolute" showEffect="{myDissolve}">
                  <mx:DataGrid x="10" y="10" width="453" dataProvider="{orders}" creationComplete="ordersRPC.send()" rowCount="6">
                  <mx:columns>
                  <mx:DataGridColumn headerText="Order #" dataField="orderID"/>
                  <mx:DataGridColumn headerText="Date Recieved" dataField="dateIn"/>
                  <mx:DataGridColumn headerText="Date Due" dataField="deliveryDate"/>
                  <mx:DataGridColumn headerText="Time Due" dataField="deliveryTime"/>
                  <mx:DataGridColumn headerText="Occasion" dataField="occasion"/>
                  <mx:DataGridColumn headerText="Status" dataField="status"/>
                  </mx:columns>
                  </mx:DataGrid>
                  <mx:Button x="10" y="160" label="Expand" click="currentState='allOrders'"/>
                  <mx:Button x="86" y="160" label="Export"/>
                  <mx:Button x="158" y="160" label="Print"/>
                  <mx:Label x="240" y="164" text="Status Search"/>
                  <mx:TextInput x="329" y="160" width="134" id="orderSearchInput" change="orderSearch()"/>
                  </mx:Panel>
                  </mx:ViewStack>
                  </mx:AddChild>
                  <mx:AddChild relativeTo="{panel1}" position="lastChild">
                  <mx:LinkBar x="188" y="12" dataProvider="mainWindow" id="linkbar1">
                  </mx:LinkBar>
                  </mx:AddChild>
                  <mx:SetStyle target="{panel1}" name="verticalCenter" value="-127"/>
                  </mx:State>
                  <mx:State name="returnCustomerNew" basedOn="main">
                  <mx:RemoveChild target="{recent}"/>
                  <mx:SetProperty target="{panel2}" name="x" value="511"/>
                  <mx:SetProperty target="{panel2}" name="title" value="Previous Orders"/>
                  <mx:RemoveChild target="{button1}"/>
                  <mx:RemoveChild target="{button2}"/>
                  <mx:RemoveChild target="{panel3}"/>
                  • 6. Re: filterfunction weirdness
                    shaungish Level 1
                    <mx:RemoveChild target="{newOrder}"/>
                    <mx:RemoveChild target="{viewOrders}"/>
                    <mx:RemoveChild target="{newCustomer}"/>
                    <mx:RemoveChild target="{mainWindow}"/>
                    <mx:RemoveChild target="{linkbar1}"/>
                    <mx:AddChild relativeTo="{panel1}" position="lastChild">
                    <mx:Panel x="10" y="10" width="493" height="470" layout="absolute" title="Add a New Order For An Existing Customer">
                    <mx:Button x="256" y="398" label="Create Order"/>
                    <mx:Button x="364" y="398" label="Cancel Order" click="currentState='main'"/>
                    <mx:Form x="0" y="40" height="350" width="473">
                    <mx:FormItem label="Description">
                    <mx:TextArea width="300" height="80"/>
                    </mx:FormItem>
                    <mx:FormItem label="Occasion">
                    <mx:ComboBox>
                    <mx:dataProvider>
                    <mx:Array>
                    <mx:String></mx:String>
                    <mx:String>Sympathy</mx:String>
                    <mx:String>Birthday</mx:String>
                    <mx:String>Anniversary</mx:String>
                    <mx:String>Baby - Boy</mx:String>
                    <mx:String>Baby - Girl</mx:String>
                    <mx:String>Get Well</mx:String>
                    <mx:String>Congratulations</mx:String>
                    <mx:String>Holiday</mx:String>
                    <mx:String>Other</mx:String>
                    </mx:Array>
                    </mx:dataProvider>
                    </mx:ComboBox>
                    </mx:FormItem>
                    <mx:FormItem label="Card Information">
                    <mx:TextArea width="300" height="80"/>
                    </mx:FormItem>
                    <mx:FormItem label="Delivery Date">
                    <mx:DateField/>
                    </mx:FormItem>
                    <mx:FormItem label="Deliver Time">
                    <mx:TextInput/>
                    <mx:RadioButtonGroup id="Time"/>
                    <mx:RadioButton label="AM" groupName="Time"/>
                    <mx:RadioButton label="PM" groupName="Time"/>
                    </mx:FormItem>
                    </mx:Form>
                    <mx:Button x="10" y="10" label="Find Customer"/>
                    <mx:Button x="316" y="10" label="Add or Find Recipient"/>
                    </mx:Panel>
                    </mx:AddChild>
                    </mx:State>
                    <mx:State name="allOrders" basedOn="main">
                    <mx:RemoveChild target="{panel3}"/>
                    <mx:RemoveChild target="{mainWindow}"/>
                    <mx:RemoveChild target="{linkbar1}"/>
                    <mx:AddChild relativeTo="{panel1}" position="lastChild">
                    <mx:Panel x="10" y="10" width="671" height="470" layout="absolute" title="All Orders" id="panel4" verticalScrollPolicy="off" horizontalScrollPolicy="off">
                    <mx:DataGrid x="10" y="40" height="380" width="631" id="allOrders" dataProvider="{orders}" change="changeHandler(event)">
                    <mx:columns>
                    <mx:DataGridColumn headerText="Order #" dataField="orderID"/>
                    <mx:DataGridColumn headerText="Date In" dataField="dateIn"/>
                    <mx:DataGridColumn headerText="Date Due" dataField="deliveryDate"/>
                    <mx:DataGridColumn headerText="Time Due" dataField="deliveryTime"/>
                    <mx:DataGridColumn headerText="Occasion" dataField="occasion"/>
                    <mx:DataGridColumn headerText="Status" dataField="status"/>
                    </mx:columns>
                    </mx:DataGrid>
                    <mx:Button x="576" y="10" label="Return"
                    click="currentState='main'"/>
                    </mx:Panel>
                    </mx:AddChild>
                    <mx:RemoveChild target="{recent}"/>
                    <mx:RemoveChild target="{panel2}"/>
                    </mx:State>
                    <mx:State name="orderDetail" basedOn="allOrders">
                    <mx:SetProperty target="{allOrders}" name="height" value="122"/>
                    <mx:AddChild relativeTo="{panel4}" position="lastChild">
                    <mx:Panel layout="absolute" title="Order#" id="orderDetail" alpha="1.0" width="631" height="250" x="10" y="170" showEffect="{myDissolve}">
                    <mx:TextArea x="337" y="129" width="264" height="71" text="Description" id="description" editable="false" cornerRadius="5"/>
                    <mx:TextArea x="337" y="62" width="264" height="59" text="Card Info" id="cardInfo" editable="false" cornerRadius="5"/>
                    <mx:Text x="337" y="34" text="occasion" width="264" id="occasion" color="#ff8000" fontWeight="bold" textAlign="left" fontSize="12"/>
                    <mx:Label x="54" y="10" text="Date In" textAlign="right"/>
                    <mx:Label x="109" y="10" textAlign="right" id="dateIn" text="dateIn"/>
                    <mx:Label x="337" y="10" text="Due" textAlign="right"/>
                    <mx:Label x="372" y="10" text="dueConcat" textAlign="right" id="dueConcat"/>
                    <mx:Label x="61" y="36" text="Status" textAlign="right"/>
                    <mx:Label x="109" y="36" text="status" textAlign="right" id="status" color="#000000" fontWeight="bold" fontSize="12"/>
                    <mx:Label x="24" y="62" text="To Customer" textAlign="right"/>
                    <mx:Label x="109" y="62" text="toCustomer" textAlign="right" id="toCustomer"/>
                    <mx:Label x="10" y="88" text="From Customer" textAlign="right"/>
                    <mx:Label x="109" y="88" text="fromCustomer" textAlign="right" id="fromCustomer"/>
                    <mx:TextArea x="10" y="129" width="319" height="71" text="Notes" id="notes" editable="false" cornerRadius="5" borderThickness="1"/>
                    </mx:Panel>
                    </mx:AddChild>
                    </mx:State>
                    </mx:states>
                    <mx:Panel layout="absolute" id="panel1" title="You are currently not logged in" height="200" verticalCenter="-292" width="250" horizontalCenter="0">
                    <mx:Label x="38" y="70" text="User Name:" textAlign="right" id="label1"/>
                    <mx:Label x="48" y="100" text="Password:" textAlign="right" id="label2"/>
                    <mx:TextInput x="117" y="68" width="103" id="username"/>
                    <mx:TextInput x="117" y="98" width="103" id="password" displayAsPassword="true"/>
                    <mx:Button x="164" y="128" label="Login" id="login" click="currentState='main'"/>
                    <mx:Image x="10" y="10" source="assets/twigs_logo.png" width="105" height="64.61539" id="twigsLogo"/>
                    </mx:Panel>

                    </mx:Application>
                    • 7. Re: filterfunction weirdness
                      shaungish Level 1
                      Sorry for so many posts... I was over the posting limit...
                      • 8. Re: filterfunction weirdness
                        BLXWebMaster Level 1
                        That's a big file. I would certainly suggest breaking it up into components. That is what makes Flex great. In any event...


                        I have made a few changes that you should be able to figure out. I included sample data so you can test, but should get the idea. Not sure if you were planning on having a search box for each column, but I consoladated it to use one serach text field that filters all three columns.

                        Also, I added the Filter Function to your Remote AR Collection. This makes it much easier to just call customers.refresh() and not a seperate function.

                        I also removed all other code so you can easily see what I am doing.

                        In the event that you still recieve the error, need to check out your actual data. Maybe dump your PHP XML to screen and post it and I will use the exact data you have as my source.

                        <mx:Application
                        xmlns:mx=" http://www.adobe.com/2006/mxml"
                        layout="absolute"
                        creationComplete="setUp()">

                        <mx:Script>
                        <![CDATA[
                        import mx.rpc.events.FaultEvent;
                        import mx.collections.ArrayCollection;
                        import mx.rpc.events.ResultEvent;

                        private var customerArray:Array =
                        [
                        {last: "Gish", first:"Shaun", home:"9723178622"},
                        {last: "Holcomb", first:"David", home:"1414"},
                        {last: "Glover", first:"Megan", home:"A"}
                        ];


                        private function customersRPCResult(event:ResultEvent):void
                        {
                        customers=event.result.customers.person;
                        customers.filterFunction=processCustomerFilter;
                        }


                        [Bindable]
                        private var customers:ArrayCollection;

                        private function setUp():void
                        {
                        customers = new ArrayCollection (customerArray);
                        customers.filterFunction=processCustomerFilter;
                        }

                        public function processCustomerFilter(item:Object):Boolean {
                        var result:Boolean=false;
                        if (
                        (textCustomer.text == '' || (item.last != null && item.last.toUpperCase().indexOf(textCustomer.text.toUpperCase()) >= 0) ||
                        ((item.first != null && item.first.toUpperCase().indexOf(textCustomer.text.toUpperCase()) >= 0)) ||
                        ((item.home != null && item.home.toUpperCase().indexOf(textCustomer.text.toUpperCase()) >= 0)))
                        )
                        {
                        result=true;
                        }
                        return result;
                        }

                        private function clearSearch():void{
                        textCustomer.text = '';
                        customers.refresh();
                        }
                        ]]>
                        </mx:Script>

                        <mx:Panel x="63" y="129" width="493" height="200" layout="absolute" title="Customer Search" id="panel3">
                        <mx:DataGrid x="10" y="36" width="453" id="customerInfo" height="114" dataProvider="{customers}" >
                        <mx:columns>
                        <mx:DataGridColumn headerText="Last Name" dataField="last"/>
                        <mx:DataGridColumn headerText="First Name" dataField="first"/>
                        <mx:DataGridColumn headerText="Phone Number" dataField="home"/>
                        </mx:columns>
                        </mx:DataGrid>
                        <mx:Label x="10" y="10" text="Customer" textAlign="right"/>
                        <mx:TextInput id="textCustomer" change="customers.refresh();" x="79" y="8"/>
                        <mx:Button x="247" y="8" label="Clear Search" click="clearSearch()"/>
                        <mx:Button x="369" y="8" label="Refresh List" />
                        </mx:Panel>

                        </mx:Application>

                        Let me know how it goes.

                        • 9. Re: filterfunction weirdness
                          shaungish Level 1
                          Yea... my next battle is 'componentizing' everything...
                          I realize I should have done it from the start, but I threw all of that together in a couple of hours because I was like 'wow I can do that...'

                          I'll try the code out... here's the xml just so you can see it and point out any issues...
                          http://twigs-floral.com/TwigsCMS/scripts/customers.php

                          Thanks for the help
                          • 10. Re: filterfunction weirdness
                            shaungish Level 1
                            Ok that worked out really well... now how do I replace the array you setup with my xml data?

                            • 11. Re: filterfunction weirdness
                              shaungish Level 1
                              I have tried every kind of databinding I can think of to try and get my actual xml file into the app, but I can't seem to get it...

                              I tried replacing the customerArray that you had setup with something like:

                              private var customerArray:Array = customersRPC.result.customers.person;

                              and that didn't work...

                              Any ideas?
                              • 12. Re: filterfunction weirdness
                                BLXWebMaster Level 1
                                O.K. I think we got it, and learned a few things. I created a php script with your XML data and got everythign working except the filter function. I was receiving the same errors you were. After a little work I discovered something. It seems that Flex and probobly the Data Type or XML does not cast as strings. So, when using the filter function along with the toUpperCase function on a column raised an error. It did not like to convert an xml data to upper case with first converting it to a string. So, I modified t he FilterFunction and everythign is working on my end.

                                Give this one a try....

                                You may want to test this application alone to make sure there is nothing wrong with your PHP. Just chnage the HTTP URL.

                                Let me know what happens.


                                <?xml version="1.0" encoding="utf-8"?>
                                <mx:Application
                                xmlns:mx=" http://www.adobe.com/2006/mxml"
                                layout="absolute"
                                creationComplete="customersRPC.send();">

                                <mx:Script>
                                <![CDATA[
                                import mx.collections.*;
                                import mx.controls.*;
                                import mx.rpc.events.*;
                                import mx.events.*;

                                [Bindable]
                                private var customers:ArrayCollection = null;
                                private function customersRPCResult(event:ResultEvent):void {
                                customers = new ArrayCollection();
                                customers = event.result.customers.person as ArrayCollection;
                                customers.filterFunction=processCustomerFilter;
                                }

                                // Fault handler - displays the error
                                private function customersRPCFaultHandler(event:FaultEvent):void
                                {
                                Alert.show(event.fault.message, "Could not load customers.php XML");
                                }

                                public function processCustomerFilter(item:Object):Boolean {
                                var result:Boolean=false;
                                if (
                                (textCustomer.text == '' || (item.last != null && String(item.last).toUpperCase().indexOf(textCustomer.text.toUpperCase()) >= 0) ||
                                ((item.first != null && String(item.first).toUpperCase().indexOf(textCustomer.text.toUpperCase()) >= 0)) ||
                                ((item.home != null && String(item.home).toUpperCase().indexOf(textCustomer.text.toUpperCase()) >= 0)))
                                )
                                {
                                result=true;
                                }
                                return result;
                                }

                                private function clearSearch():void{
                                textCustomer.text = '';
                                customers.refresh();
                                }

                                private function Filter():void{
                                textCustomer.text = '';
                                customers.refresh();
                                }
                                ]]>
                                </mx:Script>

                                <mx:HTTPService
                                id="customersRPC"
                                showBusyCursor="true"
                                url=" http://127.0.0.1/Test1/bin/customers.php"
                                result="customersRPCResult(event);"
                                fault="customersRPCFaultHandler(event);"/>

                                <mx:Panel x="63" y="129" width="493" height="200" layout="absolute" title="Customer Search" id="panel3">
                                <mx:DataGrid x="10" y="36" width="453" id="customerInfo" height="114" dataProvider="{customers}" >
                                <mx:columns>
                                <mx:DataGridColumn headerText="Last Name" dataField="last"/>
                                <mx:DataGridColumn headerText="First Name" dataField="first"/>
                                <mx:DataGridColumn headerText="Phone Number" dataField="home"/>
                                </mx:columns>
                                </mx:DataGrid>
                                <mx:Label x="10" y="10" text="Customer" textAlign="right"/>
                                <mx:TextInput id="textCustomer" change="customers.refresh();" x="79" y="8"/>
                                <mx:Button x="247" y="8" label="Clear Search" click="clearSearch()"/>
                                <mx:Button x="369" y="8" label="Refresh List" click="customers.refresh();"/>
                                </mx:Panel>

                                </mx:Application>
                                • 13. Re: filterfunction weirdness
                                  shaungish Level 1
                                  Thanks man... that was the problem... works like a charm