0 Replies Latest reply on Oct 27, 2011 6:24 AM by GIS_11

    Search/filter datagrid with webservice

    GIS_11

      I've been trying to create a search text input for my datagrid that is populated with a webservice. I've tried a few different ways like the filter function but not having much luck. Was wondering if this is even possible to do with a webservice? Here's an example of my code.

      <fx:Declarations> 

       

           <s:Webservice id="websvc"

                                 wsdl=http://localhost/SLWorkOrder/Service.asmx?wsdl

                                 showBusyCursor="true"

                                 fault="faultHandler(event)">

                <mx:operation name="GetDataSet"

                                    result="GetDataSetHandler(event)"/>

           </s:Webservice>

      </fx:Declarations>

      <fx:Script>

         

      <![CDATA[ 

      import mx.collections.ArrayCollection;

      import mx.controls.Alert;

      import mx.events.CloseEvent;

      import mx.events.DataGridEvent;

      import mx.rpc.events.FaultEvent;

      import mx.rpc.events.ResultEvent;

       

      [Bindable]

      public var dataArray:ArrayCollection = new ArrayCollection();

      private var firstTime:Boolean = true;

       

       

       

       

      private function initApp():void

      {

      // Initialize and load the web service

      websvc.loadWSDL();

      websvc.GetDataSet();

       

      }

       

      /**

      * Result event handler for websvc GetDataSetHandler call

      */

      private function GetDataSetHandler(e:ResultEvent):void

      {

      // Populate dataArray with dataset table

      dataArray = e.result.Tables.sl_Work_Orders.Rows;

      }

       

      /**

      *Fault event handler for websvc WebService call

      */

      private function faultHandler(event:FaultEvent):void

      {

      Alert.show(event.fault.message, "Application Error");

      }

       

       

       

       

      ///if the textbox is empty, it then calls back all of the data. I actually use a 'reset' button to do this as well.

       

      private function filter():void

      {

      dataArray.filterFunction = filterdataArray;

      dataArray.refresh();

      }

       

       

      private function filterdataArray(item:Object):Boolean{

      var searchString:String = myTextInput.text.toUpperCase();

      var itemName:String = (item.Complaint_Type as String).toUpperCase();

      return itemName.indexOf(searchString) > -1;

      }

       

      private function clearMyTextInput():void {

       

      if (firstTime == true )

      {

      myTextInput.text = "";

      firstTime = false;

      }

      }

       

      ]]>

      </fx:Script>

      <s:TextInput id="myTextInput" width="100%" height="26" change="filter()" enabled="true" focusIn="clearMyTextInput()" text="Filter/Search.."/>

       

      The error I get when trying to search is -  TypeError: Error #1009: Cannot access a property or method of a null object reference.