Note that there are some explanatory texts on larger screens.

plurals
  1. POSorting List without propagating event for resetting scrollbar
    text
    copied!<p>I have a spark List and using ArrayCollection as dataprovider for list. Initially when the list is populated sorting is done , but i need to add items to list quite frequently as they update on server. After i add item i have to re-sort the list. After applying sort and calling refresh() scrollbar resets itself to top. </p> <p>I am looking for a way so that i can add items to list and keep sorting the list without resetting the scrollbar to top position.</p> <p>I have read similar question earlier but in that question most users have said to store the VerticalScrollPostion in a variable and apply that VerticalScrollPosition back after the sorting is done. The problem with this is there is a jerk in scrollbar , as it goes to top after refresh and then scrolls back to position as applied. So this solution is not possible as items are added very frequently as it will make the scrollbar going up and down very frequently and annoying the users. Also does't look nice n professional</p> <p>I need a way so that scrollbar stays in it place even after sorting is done. Also i want to keep using useVirtualLayout=true for the List.</p> <p>I was also trying to extent ArrayCollection but could't find a way to solve my problem.</p> <p>Below is simple example(extracted from my main application) to illustrate the problem. Just Scroll to bottom of list and then press the Sort button(which will sort the list) and the scrollbar will jump to top position. I want scrollbar to stay at its position even after pressing Sort button:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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" minWidth="955" minHeight="600" creationComplete="application1_creationCompleteHandler(event)"&gt; &lt;fx:Declarations&gt; &lt;!-- Place non-visual elements (e.g., services, value objects) here --&gt; &lt;/fx:Declarations&gt; &lt;fx:Script&gt; &lt;![CDATA[ import mx.collections.ArrayCollection; import mx.collections.SortField; import spark.collections.Sort; [Bindable] protected var ar_c:ArrayCollection; protected var dgArray:Array=new Array(); protected function application1_creationCompleteHandler(event:FlexEvent):void { for(var i:int=0;i&lt;20;i++) dgArray.splice(-1,0,{label:"h"+i}); ar_c= new ArrayCollection(dgArray); } protected function sort_list():void{ var sort:spark.collections.Sort=new Sort(); sort.fields=[new SortField("label",false,true)]; ar_c.sort=sort; ar_c.refresh(); } ]]&gt; &lt;/fx:Script&gt; &lt;s:List x="42" y="41" id="mylist" width="199" height="253" dataProvider="{ar_c}" useVirtualLayout="true"&gt;&lt;/s:List&gt; &lt;s:Button x="295" y="40" label="Sort" click="sort_list();"/&gt; &lt;/s:Application&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload