EasyCFM.COM ColdFusion Forums / Flex Development / problem with filtering datagrid

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: problem with filtering datagrid

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

stinasius
07-18-2008 @ 7:16 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 109
Joined: Jan 2007

hi guys i came across a custom filter function that i used in my flex project. the problem here is that everything looks fine no errors but when i try to filter the datagrid nothing happens. here is my filter code.

"custom filter function"

package eu.rotundu.collections
{
     
     import mx.collections.ArrayCollection;

     public class ArrayCollectionExtended extends ArrayCollection
     {
          private var _filterFunctions:Array;
          
          public function ArrayCollectionExtended( source:Array = null )
          {
               super(source);
          }
          public function set filterFunctions( filtersArray:Array ):void
          {
               _filterFunctions = filtersArray;
               this.filterFunction = complexFilter;
          }
          public function get filterFunctions():Array
          {
               return _filterFunctions;
          }
          
          protected function complexFilter( item:Object ):Boolean
          {
               var filterFlag:Boolean = true;
               var filter:Function;
               for each(filter in filterFunctions)
               {
                    //filterFlag = (filterFlag && filter( item ));
                    if( !filterFlag )
                         break;
               }
               
               return filterFlag;
          }
     }
}

"filter code"

import mx.rpc.events.ResultEvent;               
            import mx.controls.Alert;
            import mx.managers.CursorManager;
            import flash.events.Event;
            import flash.media.*;
            import mx.collections.ArrayCollection;
            import mx.utils.ArrayUtil;
            
            /////////////data functions/////////////////////////////////////////////////////////////////
            public function InitCountry():void{
                 homeSvc.getCountries();
            }
            public function countryResult(event:ResultEvent):void{
                    ctry_cb.dataProvider = event.result;
               }
               [Bindable]
           private var cityAr:ArrayCollection = new ArrayCollection;          
               public function cityResult(event:ResultEvent):void{
                    var selectedName:String = "–-All-–";
                    
                    //var firstCityObj:Object = new Object();
                    //firstCityObj.label = "Select City";
                    //cityAr.addItemAt(firstCityObj, 0);                    
                    cityAr = event.result as ArrayCollection
                    cityAr.addItemAt(selectedName , 0);
                    cityAr.refresh();                    
                    //city_cb.dataProvider = event.result;
               }
               public function locationResult(event:ResultEvent):void{
                    lct_cb.dataProvider = event.result;
               }
           [Bindable]
           private var dataAr:ArrayCollectionExtended = new ArrayCollectionExtended;
            public function displayResult(event:ResultEvent):void{
                    dataAr = new ArrayCollectionExtended( (event.result as ArrayCollection).source);                    
               }
               /////////////end data functions/////////////////////////////////////////////////////////////////
               
               ////////////Filter Function/////////////////////////////////////////////////////////////////
               
            import eu.rotundu.collections.ArrayCollectionExtended;
            private var selectedMinPrice:int = 0;
             private var selectedMaxPrice:int = 3000000;
             private var selectedCity:String = "–-All-–";
             private var selectedLocation:String = "";
             private function creationCompleteHandler():void
             {
            /* setup the filters array: in order to take effect
             * you must call refresh() on the collection
             */
            dataAr.filterFunctions =
                [
                    filterByPrice, filterByCity,
                    filterByLocation
                ]
            dataAr.refresh();
             }
             // your classic filter functions
             private function filterByPrice( item:Object ):Boolean
             {
            if( selectedMinPrice <= item.price && selectedMaxPrice > item.price )
                return true;
            return false;
             }
        
             private function filterByCity( item:Object ):Boolean
             {
            if( item.city == selectedCity || selectedCity == "–-All-–" )
                return true;
            return false;
             }
        
             private function filterByLocation( item:Object ):Boolean
             {
            if( item.location == selectedLocation || selectedLocation == "" )
                return true;
            return false;
             }
              // change handlers, nothing new here
             private function productPriceChangeHandler():void
             {
            selectedMinPrice = priceSlider.values[0];
            selectedMaxPrice = priceSlider.values[1];
            dataAr.refresh();
             }
        
             private function cityChangeHandler():void
             {
            if( city_cb.selectedItem != null )
                selectedCity = city_cb.selectedItem.data;
            dataAr.refresh();
             }
        
             private function locationChangeHandler():void
             {
            if( lct_cb.selectedItem != null )
                selectedLocation = lct_cb.selectedItem.data;
            dataAr.refresh();
             }
               ///////////End Filter Function//////////////////////////////////////////////////////////////

"mxml remoteobject call"
RemoteObject id="homeSvc" destination="ColdFusion" source="iestate.cfcs.homes1" showBusyCursor="true" fault="CursorManager.removeBusyCursor();Alert.show(event.fault.message)"
          method name="load" result="displayResult(event)"     
          method name="getCountries" result="countryResult(event)"
          method name="getcities" result="cityResult(event)"
          method name="getlocation" result="locationResult(event)"          
     RemoteObject
any help will be appreciated

stinasius
07-21-2008 @ 9:40 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 109
Joined: Jan 2007

hi guys any help? please

stinasius
08-01-2008 @ 8:35 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 109
Joined: Jan 2007

hi guys i finally made progress on filtering a datagrid in flex. one question though, how can i use a slider that has values btn 0 and 10000 to filter prices in those ranges? thanks


Website Designed and Developed by Pablo Varando.