4 Replies Latest reply on Jul 3, 2012 8:09 AM by sadensmol

    List dataprovider refresh

    sadensmol

      Hello. I faced an issue on  AIR3.3. Is it bug? Please help me and advise.

       

      Very simple application for test

       

      <fx:Script>

                          <![CDATA[

                                    import mx.collections.ArrayCollection;

                                    import mx.events.FlexEvent;

       

                                    import spark.collections.Sort;

       

                                    private var testCollection:ArrayCollection = new ArrayCollection();

       

                                    protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void {

                                                        testCollection.addItem("111");

                                                        testCollection.addItem("222");

                                                        testCollection.addItem("333");

       

                                                        var sort:Sort = new Sort();

                                                        sort.compareFunction = compareFunctionSort;

                                                        testCollection.sort = sort;

       

       

                                    }

       

                                    private function compareFunctionSort (obj1:Object, obj2:Object,fields:Array = null) :int {

                                              return 0;

                                    }

       

                                    protected function button1_clickHandler(event:MouseEvent):void {

                                              testCollection.refresh();

                                    }

       

                          ]]>

      </fx:Script>

       

      <s:layout>

        <s:VerticalLayout/>

        </s:layout>

       

                <s:List dataProvider="{testCollection}" itemRenderer="TestItemRenderer">

        <s:layout>

                                    <s:TileLayout id="usersListLayout" horizontalGap="5" verticalGap="5" horizontalAlign="left" verticalAlign="top" />

        </s:layout>

        </s:List>

                <s:Button label="1" click="button1_clickHandler(event)"/>

       

       

      Here is an item renderer:

      <s:BorderContainer >

        <s:layout>

        <s:VerticalLayout/> 

        </s:layout>

                          <s:Label text="{data}"/>

                          <s:Label text="{DebugUtils.getObjectMemoryHash(videoC)}"/>

        <mx:UIComponent id="videoC"/>

      </s:BorderContainer>

       

      After clicking on Button collection going to refresh. But always 0 returns from sort function!!!

      And what i see ( please check images )

       

      Initially:

      Screen Shot 2012-07-03 at 3.10.29 PM.png

      After click:

      Screen Shot 2012-07-03 at 3.10.40 PM.png

       

      wtf?

        • 1. Re: List dataprovider refresh
          tinylion_uk Level 2

          Your sort function isn’t doing anything.

           

           

           

          You aren’t actually doing a compare in there

           

           

           

          You need to compare the inputs and return a value dependant on the code in the method. You are telling it to do nothing.

           

           

           

          You need to follow the following rules

           

          Return value

           

          -1, if a should appear before b in the sorted sequence

           

          0, if a equals b

           

          1, if a should appear after b in the sorted sequence

          • 2. Re: List dataprovider refresh
            tinylion_uk Level 2

            And before writing WTF, try writing ‘google’

             

            Just do a search for arrayCollection compareFunction

             

            Lots of examples of how the compareFunction works.

            • 3. Re: List dataprovider refresh
              sadensmol Level 1

              Thank you for quick answer.

               

              Sorry for that hasty expression but there is not clearly behaivor.

               

              If i invoke collection.refresh() and no sort is needed for my collection it returns 0 in any combinations of items. So i get the same result incorrect visualisation of list.

              Going to ask google about arrayCollection compareFunction...

              • 4. Re: List dataprovider refresh
                sadensmol Level 1

                So Ive rewritten my sort function in according with first result from google

                http://stackoverflow.com/questions/1602385/sorting-an-arraycollection-in-flex

                 

                                              private function compareFunctionSort (a:Object, b:Object,fields:Array = null) :int {

                                                        var cmpArray:Array = ["111", "222", "333"];

                                                        var aValue:Number = cmpArray.indexOf(a);

                                                        var bValue:Number = cmpArray.indexOf(b);

                                                        if(aValue == bValue)

                                                                  return 0;

                                                        if(aValue > bValue)

                                                                  return 1;

                                                        return -1;

                                              }

                 

                but got the same result. Visualization works incorrectly!!!

                 

                Please have a look at the attached video