5 Replies Latest reply on Oct 17, 2010 3:46 PM by Shongrunden

    Flex Spark List scroll to bottom when new data is added


      I have a Spark List (spark.components.List) backed by an  ArrayCollection for its dataProvider. The List has a vertical scrollbar  when there's too many rows to display. What I want is when a new row is  added to the List for it to scroll to the bottom to show that new row.


      I've tried calling List's ensureIndexIsVisible from a  listener on the ArrayCollection. This doesn't work because the List  hasn't yet fully rendered the new row. It will either scroll to the  second from the last row, or throw the exception:


      Error: invalidIndex

      at spark.layouts.supportClasses::LinearLayoutVector/start()[E:\dev\4.0.0\frameworks\projects \spark\src\spark\layouts\supportClasses\LinearLayoutVector.as:893]

      at spark.layouts.supportClasses::LinearLayoutVector/getBounds()[E:\dev\4.0.0\frameworks\proj ects\spark\src\spark\layouts\supportClasses\LinearLayoutVector.as:1117]

      at spark.layouts::VerticalLayout/getElementBounds()[E:\dev\4.0.0\frameworks\projects\spark\s rc\spark\layouts\VerticalLayout.as:852]

      at spark.layouts.supportClasses::LayoutBase/http://www.adobe.com/2006/flex/mx/internal::getScrollPositionDeltaToElementHelper()[E:\dev \4.0.0\frameworks\projects\spark\src\spark\layouts\supportClasses\LayoutBase.as:1367]

      at spark.layouts.supportClasses::LayoutBase/getScrollPositionDeltaToElement()[E:\dev\4.0.0\f rameworks\projects\spark\src\spark\layouts\supportClasses\LayoutBase.as:1348]

      at spark.components::List/ensureIndexIsVisible()[E:\dev\4.0.0\frameworks\projects\spark\src\ spark\components\List.as:2105]

      I've made sure that my listener is added to the ArrayCollection after  setting List's dataProvider. The hope is that I'd be calling ensureIndexIsVisible after the List got a chance to process the new row. My guess is that  the List doesn't render the row until some redraw event that occurs  later (after I've called ensureIndexIsVisible).


      I've also tried specifying a VerticalLayout and setting its verticalScrollPosition to an overly large number (like 99999). This has the same problem - it scrolls to the second from the last row.


      So, is there a way to scroll to a newly added row in a Spark List?


      Thanks, Steve