0 Replies Latest reply on Feb 8, 2007 10:02 AM by FRBAmy

    Can you filter on numeric field?

    FRBAmy
      I am trying to filter a field containing numbers, but I can't get it to work. I am doing something similar to the code below, but the name field in my code is a numeric identification field. Can anyone help??

      This is the code from Ben Forta:

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

      <mx:Script>
      <![CDATA[

      // On startup
      public function initApp():void
      {

      // Set filter function // Be careful to set filterFunction // only after ArrayCollection has been // populated.
      myData.filterFunction=processFilter;
      }

      // Filter function
      public function processFilter(item:Object):Boolean
      {
      var result:Boolean=false;

      // If no filter text, or a match, then true
      if (!item.name.length
      || item.name.toUpperCase().indexOf(txtFilter.text.toUpperCase()) >= 0)
      result=true;

      return result;
      }
      ]]>
      </mx:Script>

      <!-- Data (use ArrayCollection) -->
      <mx:ArrayCollection id="myData">
      <mx:source>
      <mx:Object name="Ben Forta" location="Oak Park, MI" phone="(248)555-5555" />
      <mx:Object name="Jane Doe" location="New York, NY" phone="(212)555-1234" />
      <mx:Object name="Jim Jones" location="Atlanta, GA" phone="(414)555-1212" />
      <mx:Object name="Roberta Roberts" location="Chicago, IL" phone="(312)555-4321" />
      <mx:Object name="Steve Stevens" location="Boston, MA" phone="(617)555-5656" />
      </mx:source>
      </mx:ArrayCollection>

      <!-- UI -->
      <mx:HBox width="100%">
      <mx:Label text="Filter:"/>
      <mx:TextInput id="txtFilter" width="100%"
      change="myData.refresh()"/>
      </mx:HBox>
      <mx:DataGrid dataProvider="{myData}"
      width="100%" height="100%">
      <mx:columns>
      <mx:DataGridColumn headerText="Name"
      dataField="name"/>
      <mx:DataGridColumn headerText="Location"
      dataField="location"/>
      <mx:DataGridColumn headerText="Phone"
      dataField="phone"/>
      </mx:columns>
      </mx:DataGrid>

      </mx:Application>