1 Reply Latest reply on Nov 27, 2008 10:32 PM by nagarjunaakkineni

    DataGrid search

      Hi All,
      I am using below code it's working fine.Still one issue is there.If i have 4 data grid columns and if don't have data for any one column search is not working.It's working fine till data is there in every column of grid.What will be the solution for this?

      this is my MXML code..

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientColors="[#FFFFFF, #FFFFFF]"
      horizontalAlign="center" initialize="testXML.send()" viewSourceURL="srcview/index.html">

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

      [Bindable] private var userList:ArrayCollection;

      private function resultHandler(event:ResultEvent):void {
      userList = (event.result.users.user);
      }

      private function searchUsers():void{
      userList.filterFunction = filterUsers;
      userList.refresh();
      }

      private function filterUsers(item:Object):Boolean
      {
      var isMatch:Boolean = false
      if(item.firstName.toLowerCase().search(search.text.toLowerCase()) != -1)
      {
      isMatch = true
      }
      else if(item.emailAddress.toLowerCase().search(search.text.toLowerCase()) != -1)
      {
      isMatch = true
      }
      return isMatch;
      }


      private function clear():void{
      userList.filterFunction = null;
      userList.refresh();
      search.text = '';
      }
      ]]>
      </mx:Script>

      <mx:HTTPService id="testXML" url="data/data.xml" result="resultHandler(event)"/>

      <mx:VBox id="container" paddingTop="10" paddingLeft="10" width="100%" horizontalAlign="center">

      <mx:Form>
      <mx:FormItem label="Search Names" direction="horizontal">
      <mx:TextInput id="search" change="searchUsers()" />
      <mx:Button label="Clear Search" click="clear()" />
      </mx:FormItem>
      </mx:Form>

      <mx:DataGrid id="dg" dataProvider="{testXML.lastResult.users.user}" width="400">
      <mx:columns>
      <mx:DataGridColumn headerText="Name" dataField="firstName" id="firstName"/>
      <mx:DataGridColumn headerText="Email Address" dataField="emailAddress" id="emailAddress"/>
      </mx:columns>
      </mx:DataGrid>
      </mx:VBox>

      </mx:Application>

      this is the XML file

      <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
      <users>
      <user>
      <firstName>Anthony</firstName>
      <emailAddress>senorAnthony@gmail.com</emailAddress>
      </user>
      <user>
      <firstName>Citlali</firstName>
      <emailAddress>TheBestGirlieGirl@gmail.com</emailAddress>
      </user>
      <user>
      <firstName>Marc</firstName>
      <emailAddress>MarcTheMan@gmail.com</emailAddress>
      </user>
      <user>
      <firstName>Ajay</firstName>
      <emailAddress>AjayWerd@gmail.com</emailAddress>
      </user>
      <user>
      <firstName>John</firstName>
      <emailAddress>johnWhatever@gmail.com</emailAddress>
      </user>
      </users>

      if suppose "emailAddress" is not there in my XML file datagrid is not working.......

      will you Please suggest solution for my problem?
      Regards
      Nag