3 Replies Latest reply on Apr 28, 2010 9:56 PM by MatHadder

    filterfunction

    GeorgeWS Level 1

      I have a RO that gets some data a few months of data. I want to show one month at a time. I made a slider that can change the months. So I have a bar chart that shows 4 people and when I move the slider it shows how well each person did for the selected month. Works great... but when the data is loaded it shows all months, when I move the slider it shows just the selected month and then works perfectly. How can it be filtered or refreshed from the start?

       

      public

       

       

       

       

       

      function handleQueryResult5(event:ResultEvent):void{

      myChart=event.result

      as ArrayCollection;

      myChart.filterFunction = sliderFilterFunc;

      }

       

       

      private var months:ArrayCollection = new ArrayCollection([

       

      "January", "February", "March", "April", "May", "June",

       

      "July", "August", "September", "October", "November",

       

      "December"

      ]);

       

       

       

      private function getSliderLabel(num:Number):String{

       

      return months.getItemAt(num-1) as String;

      }

       

       

      public function getCurrentMonth():Array{

       

      return [new Date().getMonth()+1];

      }

       

       

      private function slider_change(evt:SliderEvent):void {

      myChart.refresh();

      }

       

       

      private function sliderFilterFunc(item:Object):Boolean {

       

      var minSlider:uint = slider.values[0];

       

      var result:Boolean=false;

       

      var pattern:RegExp = new RegExp("^"+myReport2.selectedValue,"i");

       

      if(!item[String("Status")].length

      || item[String(

      "Status")].match(pattern) &&

      (item.value == minSlider))

       

      {

      result=

      true;

      }

       

      return result;

      }

        • 1. Re: filterfunction
          SpaghettiCoder Level 3

          creationComplete="onCreationComplete()"

           

          call a function that does the filtering either on the creation complete, or if you are retreiving data, as the last thing in your resultHandler for the returned data.

          • 2. Re: filterfunction
            GeorgeWS Level 1

            I was trying that for the resultHandler but that just gives me an error: 1009 cannot access property or method of a null object ref.

             

            I was adding myChart.refresh() to the resultHandler. When I take it out there are no errors.

            • 3. Re: filterfunction
              MatHadder

              Sounds like something the filter function uses is null when the results are first returned?

               

              private var _filterInvalid:Boolean = false;

               


              function handleQueryResult5(event:ResultEvent):void{

               

              myChart=event.result

               

              as ArrayCollection;

               

              myChart.filterFunction = sliderFilterFunc;

               

              _filterInvalid = true;
              this.invalidateProperties();

               

              }

               

              private function slider_change(evt:SliderEvent):void
              {

               

              _filterInvalid = true;
              this.invalidateProperties();

               


              }

               


              override protected function commitProperties():void
              {
              super.commitProperties();

               

              if( _filterInvalid && myChart != null && slider != null && slider.values != null && slider.values.length > 0 )
              {
              myChart.refresh();
              _filterInvalid = false;

               

              }

               


              }

               


              Also, you might also want to have your filter function check that things are not null before using their sub properties.