5 Replies Latest reply on May 28, 2008 12:04 PM by Idriel

    Filter DataGrid

      I have found lot's od dataGrid filter's but look's like non of it works for me.

      I have DataGrid (populate from XML).
      then one textBox (filter part or whole word)
      ComboBox (by what column to filter).
      -> returned filterd DataGrid

      if you have some good page that have example like this. Thanks I need. it.
      I look from books. and from few examples. but none worked for me.
        • 1. Re: Filter DataGrid
          Idriel Level 1
          Any help here.
          I am going over many examples. and every time everything fall beacuse I got date from XML.

          Is there some good example. Thanks. Or some book that have all that.
          • 2. Re: Filter DataGrid
            ntsiii Level 3
            Often with Date, because of the different formats, you must write a custom filter function.

            Explain what "none worked" and "fail" mean. What happend or does not happen. Why? which line of code? Post the failing code.

            • 3. Re: Filter DataGrid
              Idriel Level 1
              XML file Test.xml

              // I put for XML
              <mx:HTTPService id="Test" url="Test.xml" resultFormat="e4x" result="onResult(event)" />
              // (Then I have populate dataGrid with <mx:XMLListtCollection.....> but if I make like than then I dont know how to make from that ArrayColetion to make filter possible so I tried like this) So I Try like this ( I wanna sort by second column called "Name")
              import mx.events.FlexEvent;
              import mx.collections.ArrayCollection;
              import mx.rpc.events.ResultEvent;
              // ControlBox Array
              private var cbFilter: Array = [ {label:"Name"}, {label:"Id"}];
              //Test Filter 2

              private var TestXML:ArrayCollection;
              private function initApp():void {
              private function onResult(evt:ResultEvent):void {
              this.TestXML = evt.result.data.region;
              private function sortRanges(obj1:Object, obj2:Object):int{
              var value1:Number = obj1.range.range1;
              var value2:Number = obj2.range.range1;

              if(value1 < value2) {
              return -1;
              else if(value1 > value2){
              return 1;
              else {
              return 0;
              private function applyFilter():void {
              if(this.TestXML.filterFunction == null) {
              this.TestXML.filterFunction = this.filterName;
              private function filterName(item:Object):Boolean {
              var match:Boolean = true;

              if(txtFilter.text != "") {
              var city:String = item["Name"];
              var filter:String = this.txtFilter.text;
              if(!city ||
              city.toLowerCase().indexOf(filter.toLowerCase()) < 0) {
              match = false;
              return match;

              <mx:TextInput x="10" y="41" width="146" id="txtFilter" toolTip="Enter text for filtering DataGrid" change="applyFilter()"/>

              <mx:DataGrid x="10" y="71" width="210" height="389" id="dgTest" dataProvider="{TestXML}" allowMultipleSelection="false" resizableColumns="true" showHeaders="true" sortableColumns="true">
              <mx:toolTip>DataGrid for displaying Locations and for filtering.</mx:toolTip>
              <mx:DataGridColumn width="70" headerText="Id" dataField="ID"/>
              <mx:DataGridColumn width="140" headerText="Name" dataField="NAME"/>

              // when I open this I got errors and DataGrid is empty.
              • 4. Re: Filter DataGrid
                Idriel Level 1
                I have event this page about DG that have good exmaples.

                But I know that I can make from HTTPService to parse it in object.
                How to parse that object into Array Collection.
                • 5. Re: Filter DataGrid
                  Idriel Level 1

                  Problem was here in AS. All I need was little more google. :D

                  this.TestXML = evt.result.Testing.Record