2 Replies Latest reply on Aug 23, 2006 10:13 AM by GeorgeWS

    filtering

    GeorgeWS Level 1
      I have a text input that filters a grid. I want to add a drop down box to select the column the text box filters on. Right now I have it so it filters on the PDES5W column. How can I enable the drop down to take the place of the PDES5W?

      This is what I have:

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

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

      [Bindable]
      public var myData:ArrayCollection;

      [Bindable]
      public var aReturnTypes: Array = [ {label:"query", data:"query"} ];

      [Bindable]
      public var returnType:String="string";

      public function clearAll():void{

      myData=new ArrayCollection();
      }

      public function handleQueryResult(event:ResultEvent):void{
      myData=event.result as ArrayCollection;
      myData.filterFunction=processFilter;
      }
      ]]>
      </mx:Script>

      <mx:Script>
      <![CDATA[
      public function initApp():void
      {
      }

      public function processFilter(item:Object):Boolean
      {
      var result:Boolean=false;
      var pattern:RegExp= new RegExp("^"+txtFilter.text,"i");
      if (!item.PDES5W.length
      || item.PDES5W.match(pattern))
      result=true;

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

      <mx:Script>
      <![CDATA[

      [Bindable]
      public var myfilter: Array = [ {label:"Product ID", data:1},
      {label:"Description", data:2}, {label:"Size", data:3}, {label:"Pack", data:4} ];

      [Bindable]
      public var selectedItem:Object;
      ]]>
      </mx:Script>

      <mx:RemoteObject
      id="qResult"
      destination="ColdFusion"
      source="Inventory"
      showBusyCursor="true"
      >

      <mx:method name="Inventory" result="handleQueryResult(event)" fault="Alert.show(event.fault.message)"/>

      </mx:RemoteObject>

      <mx:Panel title="Inventory" height="90%" width="100%"
      paddingTop="5" paddingLeft="5" paddingRight="5" paddingBottom="5" cornerRadius="10" roundedBottomCorners="true">


      <mx:HBox width="100%">
      <mx:Label text="Filter:"/>
      <mx:TextInput width="100" id="txtFilter" change="myData.refresh()" />
      <mx:ComboBox dataProvider="{myfilter}" width="125"
      close="selectedItem=ComboBox(event.target).selectedItem"/>
      <mx:RadioButton label="Warehouse" click="accordion.selectedIndex=0;" selected="true"/>
      <mx:RadioButton label="Cash / Carry" click="accordion.selectedIndex=1;"/>
      <mx:RadioButton label="Storage" click="accordion.selectedIndex=2;"/>
      <mx:Spacer width="100%" height="20"/>
      <mx:Button label="Print" />
      </mx:HBox>

      <mx:Accordion id="accordion" width="100%" height="100%" headerHeight="5">
      <mx:VBox height="100%" >
      <mx:DataGrid dataProvider="{myData}" initialize="qResult.Inventory()" width="100%" height="100%">
      <mx:columns>

      <mx:DataGridColumn dataField="PNUM5W" headerText="Prod ID" width="55"/>
      <mx:DataGridColumn dataField="PDES5W" headerText="Desc" width="163"/>
      <mx:DataGridColumn dataField="SDIVDE" headerText="Size" width="50"/>
      <mx:DataGridColumn dataField="ISCF3W" headerText="Pac" width="35"/>
      <mx:DataGridColumn dataField="DIVN5W" headerText="Rnk" width="35"/>

      <mx:DataGridColumn dataField="INV_11" headerText="Or Inv" width="50"/>
      <mx:DataGridColumn dataField="ORD_11" headerText="Or Ord" width="50"/>
      <mx:DataGridColumn dataField="DAT_11" headerText="Or Due" width="50"/>
      <mx:DataGridColumn dataField="INT_11" headerText="Or InT" width="50"/>

      <mx:DataGridColumn dataField="INV_31" headerText="Ch Inv" width="50"/>
      <mx:DataGridColumn dataField="ORD_31" headerText="Ch Ord" width="50"/>
      <mx:DataGridColumn dataField="DAT_31" headerText="Ch Due" width="50"/>
      <mx:DataGridColumn dataField="INT_31" headerText="Ch InT" width="50"/>

      <mx:DataGridColumn dataField="INV_41" headerText="MH Inv" width="50"/>
      <mx:DataGridColumn dataField="ORD_41" headerText="MH Ord" width="50"/>
      <mx:DataGridColumn dataField="DAT_41" headerText="MH Due" width="50"/>
      <mx:DataGridColumn dataField="INT_41" headerText="MH InT" width="50"/>

      </mx:columns>
      </mx:DataGrid>
      </mx:VBox>
      </mx:Accordion>
      </mx:Panel>
      </mx:Application> PDES5W