0 Replies Latest reply on Jan 30, 2013 10:04 AM by gigibatta

    how to filter spark datagrid?

    gigibatta

      SORRY, I TRY TO FILTER MY DATAGRID, BUT IT DOESN'T WORK.

      WHAT'S WRONG IN THIS CODE?

      IN THE DEBUG EVERYTHING IS OK UNTIL THE BOLD TEXT, BECAUSE THE DATAPROVIDER IN DATAGRID IS NOT FILTERED.

      PLEASE HELP ME!!!

      THANK YOU.

       

      <?xml version="1.0" encoding="utf-8"?>

      <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"

              xmlns:s="library://ns.adobe.com/flex/spark" title="Albo" creationComplete="init(event)">

       

          <fx:Script>

              <![CDATA[

                  import mx.events.FlexEvent;

                  import spark.events.GridEvent;

                  import spark.events.TextOperationEvent;           

                  import spark.components.TextInput;           

                  import spark.components.DataGrid;

                  import mx.collections.ArrayList;

       

       

                  protected function init(event:FlexEvent):void

                  {

                      IngegneriXML.send();

                  }

       

                  private function gridClickEvent(event:GridEvent):void

                  {

                      navigator.pushView(Dettaglio, event.target.selectedItem);

                  }

       

                  private function filterDataProvider(obj:Object, idx:int, arr:Array):Boolean

                  {

                      var txt1:String = RicCogn.text;

                      var txt2:String = obj._item.cognome.toString();

                  if (txt1.toLowerCase() == txt2.toLowerCase())

                      {

                      return true;

                      }               

                      return false;

                  }   

       

                  protected function RicCogn_changeHandler(event:TextOperationEvent):void

                  {

                      var arr:Array = Grid1.dataProvider.toArray();

                      var filteredArr:Array = arr.filter(filterDataProvider);

                      Grid1.dataProvider =  new DataProvider(filteredArr);

                      Grid1.dataProvider.refresh();

                      var ara2:Array = Grid1.dataProvider.toArray();

                      var ara3:Array = Grid1.dataProvider.toArray();

                  }

       

              ]]>

          </fx:Script>   

          <fx:Declarations>

              <s:HTTPService id="IngegneriXML" url="C:\AlboFlash\DatiXML\ingegneri.xml"/>

          </fx:Declarations>

          <s:TextInput x="0" y="0" id="RicCogn" change="RicCogn_changeHandler(event)"/>

          <s:DataGrid id="Grid1" x="0" y="80" dataProvider="{IngegneriXML.lastResult.ingegneri.ingegnere}" height="100%" width="100%" gridClick="gridClickEvent(event);">

              <s:columns>

                  <s:ArrayList id="columns">

                      <s:GridColumn dataField="cognome" headerText="Cognome" minWidth="100"/>

                      <s:GridColumn dataField="nome" headerText="Nome" minWidth="100"/>

                  </s:ArrayList>

              </s:columns>

          </s:DataGrid>

       

      </s:View>