6 Replies Latest reply on Jan 6, 2010 3:48 PM by tehxike1

    Grid's selectedItems is broken after filterFunction

    tehxike1 Level 1

      I have a grid bound to an ArrayCollection that has a filterFunction.  If I filter the collection, reset the grid's selectedItems (selectedItems = []), then click an item, the grid's selectedItems array is empty.  Here's the smallest app I could write to demonstrate the problem:


      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     minWidth="1024" minHeight="768"
                     initialize="initHandler(event)" >
                  import mx.collections.ArrayCollection;
                  import mx.events.FlexEvent;
                  import mx.events.ListEvent;
                  import spark.events.TextOperationEvent;
                  [Bindable] private var dp:ArrayCollection;
                  private function initHandler(event:FlexEvent):void
                      dp = new ArrayCollection(["first","second","third","fourth","fifth","sixth","seventh","eighth"]);
                      dp.filterFunction = filterFunction;
                  private function filterTxt_changeHandler(event:TextOperationEvent):void
                      grid.selectedItems = [];
                  private function filterFunction(item:String):Boolean
                      if (filterTxt.text.length > 0)
                          return item == filterTxt.text;
                          return true;
                  private function grid_itemClickHandler(event:ListEvent):void
                      grid2.dataProvider = grid.selectedItems;
              <s:TextInput id="filterTxt" change="filterTxt_changeHandler(event)" />
          <ns:DataGrid id="grid" dataProvider="{dp}" itemClick="grid_itemClickHandler(event)">
                  <ns:DataGridColumn dataField="name" headerText="name" />
          <s:Label text="Selected Items:" />
          <ns:DataGrid id="grid2" >
                  <ns:DataGridColumn dataField="name" headerText="name" />


      To reproduce the problem with this code:

      1) click an item- notice that selectedItems is showing up properly in the lower grid

      2) type something in the textinput, then delete it

      3) click another item- notice that no selectedItems are showing up anymore in the lower grid