Flex – Preventing DataGrid scrolling when the dataprovider is updated.

Premarin For Sale Acomplia No Prescription Buy Tulasi No Prescription Buy Online Vantin Buy Female Viagra Online Amaryl For Sale Ashwagandha No Prescription Buy Soma No Prescription Buy Online Cystone Buy High Love Online Femara For Sale Mevacor No Prescription Buy Zyloprim No Prescription Buy Online Crestor Buy Glucophage Online Purinethol For Sale Amitriptyline No Prescription Buy Prednisone No Prescription Buy Online Wellbutrin Buy Yerba Diet Online Lasix For Sale Tramadol No Prescription Buy Effexor No Prescription Buy Online Depakote Buy Cialis Jelly Online

I was having issues with my DataGrid scrolling to the top when my grid updated from the server. It is very aggravating as a user when you are milling about and *BAM* it scrolls away.

This worked:

var storeItemForUpdate:ItemVO = grid.selectedItem;;
var vScroll:int = grid.verticalScrollPosition;
arrayCollection.source = updatedDataArray
grid.validateNow();
grid.verticalScrollPosition = vScroll;
grid.selectedItem = storeItemForUpdate;

The current selection is stored, the scroll position is stored, the grid is updated, validated, and then the stored variables are applied without so much as a flicker on the screen for the user. Much better.

Related Posts

Updated: Continuous scrolling image thumbnail and slideshow component for Flex., Complex DataGrid filterFunction in Flex/Air, Continuous scrolling image thumbnail component for Flex., Adding a ToolTip function to a ComboBox in Flex, Continuous scrolling image thumbnail and slideshow component for Flex.

6 Responses to “Flex – Preventing DataGrid scrolling when the dataprovider is updated.”


  1. 1 Joel

    I found that it is easier to update the dataProvider with itemUpdated and make proper use of collections in Flex. This is still a solution if that isn’t possible, for whatever reason, but I’d say it is far from a best practice.

  2. 2 Hari

    Hi, my datagrid is bound to an ArrayCollection which is the dataprovider. When I remove items from Arraycollection, the focus on the datagrid moves to the bottom of the grid which deiplays a blank row. I want the focus to be remained always at the top. Please let me know any way to solve this.

  3. 3 Joel

    I’ve never seen it go to the bottom like that!

    If you want it to go to the top, do this:

    myDataGrid.selectedIndex = 0
    myDataGrid.scrollToIndex(0)

    That will reposition and select the first entry. To make it ’smart’ you want to record the position of the item you are deleting, and have it select/scroll there.

  4. 4 Chris

    Joel,

    could you post the code where this is implemented? This is something I have been looking for. Thanks for the help!

  5. 5 tsedeke

    Joel,
    in some cases you are right, but if you have an application getting data from database where also many people work on, it is important to read all records after changing, cause not only your record may change.
    In this situation you have no other chance, you have to remember your key of your record and after refresh find and select it again.
    Cause today we are not able to make a specific record update in a Arraycollection from a database.
    Ok you can do it, but it is not save and cause an overhead.

    Thorsten

  6. 6 dj brikz

    hi…thanks for the post…it works well in the application that i’m doing now. my application is fetching entries from the database and updates the datagrid every 1 second.

    Wrap up solution:

    1. Before updating the data provider of the datagrid, retrieve first the verticalScrollPosition and selectedItem properties of the datagrid.
    2. Update the data provider of the datagrid.
    3. Set again the datagrid verticalScrollPosition and selectedItem properties using the values you stored in step 1.
    4. That’s all and enjoy.

Leave a Reply