[ 
https://issues.apache.org/jira/browse/FLEX-23974?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13637427#comment-13637427
 ] 

Mark Kessler commented on FLEX-23974:
-------------------------------------

Test application that reproduces issue and shows correctly working spark 
datagrid for comparison.  No idea why you need to reference the ItemRenderer to 
get an index from it before setting a new index....

<?xml version="1.0" encoding="utf-8"?>
<!---
   Test application
-->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009";
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx" > 

    <fx:Script>
        <![CDATA[
                        import mx.collections.ArrayCollection;

            [Bindable]
                        protected var items:ArrayCollection = new 
ArrayCollection([{Country:"SPAIN"},{Country:"CARTAGO"},{Country:"AMERICA"},{Country:"AUSTRALIA"}]);

                        protected function onApplyFilter(event:Event):void {
                                items.filterFunction = filter;
                                items.refresh();
                                datagrid_id.selectedIndex = 0;
                                datagrid_id2.selectedIndex = 0;
                        }

                        protected function filter(o:Object):Boolean {
                                if(String(o.Country).indexOf("RAL") == -1){
                                        return false;
                                }
                                return true;
                        }
        ]]>
    </fx:Script>

    <s:layout>
        <s:VerticalLayout horizontalAlign="center" verticalAlign="middle" 
gap="0" />
    </s:layout>

    <s:Label text="MX DataProvider showing issue" />
    <mx:DataGrid id="datagrid_id" dataProvider="{items}" width="300" 
height="200">
    </mx:DataGrid>
    
    <mx:Button id="applyFilter" label="Apply Filter" 
click="onApplyFilter(event)" />
    <mx:Label text="1. selectedIndex: {datagrid_id.selectedIndex}" />

    <mx:Spacer height="30" />
    
    <s:Label text="Spark DataProvider for comparison" />
    <s:DataGrid id="datagrid_id2" dataProvider="{items}" width="300" 
height="200">
    </s:DataGrid>
    <mx:Label text="2. selectedIndex: {datagrid_id2.selectedIndex}" />

</s:Application>

                
> Datagrid with ArrayCollection provider, error at setter of selectedIndex 
> after applying filters to the ArrayCollection
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: FLEX-23974
>                 URL: https://issues.apache.org/jira/browse/FLEX-23974
>             Project: Apache Flex
>          Issue Type: Bug
>          Components: mx: DataGrid
>    Affects Versions: Adobe Flex SDK 3.2 (Release)
>         Environment: Affected OS(s): Windows
> Affected OS(s): 
> Browser: Firefox 3.x
> Language Found: English
>            Reporter: Adobe JIRA
>
> Steps to reproduce:
> 1. Create a DataGrid with DataProvider an ArrayCollection
> 2. Full the ArrayCollection with N items
> 3. Apply a filter to the ArrayCollection that only one item is shown (not in 
> position 0)
> 4. set the datagrid selectedIndex to 0
>  
>  Actual Results:
>  the datagrid selectionIndex is set to the last known position of the item 
> instead to 0
>  
>  
>  Expected Results:
>  datagrid selectionIndex = 0
>  
>  
>  Workaround (if any):
>  After Applying the filters to the arrayCollection use 
> datagrid.validateNow(); before settin selectionIndex to 0
>  
>  
>  ------
> Information found when debugging the flex api.
> DATAGRID BEFORE APPLYING FILTERS
> * SPAIN
> * CARTAGO
> * AMERICA
> * AUSTRALIA
> filter: name cotains "RAL"
> DATAGRID AFTER APPLYING FILTERS
> * AUSTRALIA
> the piece of code:
> -------
> acResultats.filterFunction = componentFiltre.objectBelongFilters;
> acResultats.refresh();
> if(acResultatsFiltrats.length > 0){
>       //datagrid_id.validateNow();  <-- Uncomment this to allow the app to 
> work fine
>       datagrid_id.selectedIndex = 0;
>       itemClicked();
> }
> -------
> When debugging the line datagrid_id.selectedIndex = 0; the collection 
> attribute is correctly set to only 1 element in the array and the length set 
> to 1. So it follow the code road:
> * selectedIndex = 0
> ---> commitSelectedIndex(value)
> ------> selectItem(item:UIDToItemRenderer(uid), false, false);
> ---------> var index:int = itemRendererToIndex(item)
> and this returns the older position of the item, instead the new one setted 
> on its property index, so item has the real information but instead using it, 
> it uses a value returned by the function itemRendererToIndex.
> --

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to