So are you doing something like the following?
function refreshDataGrid() : void {
myService.loadPeople();
}
function peopleLoaded( event : DynamicEvent ) : void {
// save off the index
var selectedIndex : int = dataGrid.selectedIndex;
// now swap out the model
dataGrid.model.source = event.people;
dataGrid.refresh();
// now that your model is reloaded restore the selection
dataGrid.selectedIndex = selectedIndex;
dataGrid.scrollToIndex( dataGrid.selectedIndex );
}
Or are you getting the selectedIndex before you make the call to the server?
If it's the later then change it to the former because once you're inside
the peopleLoaded method. The user can't mess with the UI while that method
is being run so you're not going to get into a situation where it loses the
selection, or restores the old selection if the user messes with the
selection after making the call to the server.
Things to keep in mind about this. Saving indexes is not a good practice,
and in fact if you're loading completely new objects it only works provided
the order and size are the same as prior to loading the objects. You can't
use selectedItem call either because you're dumping all of your objects you
had prior to loading them from the server (might explain why your restore
isn't working). While they might be the same in terms of database identity,
they are not the same instances. It's better to save off the database ID of
the object then search for that object in your array and restore that index.
Either way, you have a serious performance problem on your client or the
server. Loading 321 objects is child's play for most systems so the fact
that is taking a long time makes me think either you're loading too much
information at once, or something else is slowing it down. Have you tried
hard coding the list returned on the server instead of hitting the database?
If that was fast then you know it's something in how you're retrieving the
data. Maybe save off the XML, JSON, responses from the server to a text
file and try returning that to the client. See how long it takes. If it's
fast then you know it's the database. If it's slow then it must be on the
client or in the transferring of the objects.
Charlie
On Fri, Oct 30, 2009 at 2:13 PM, Sarah Davidson <[email protected]> wrote:
> Since you were so nice last time, I thought I might take another chance
> with another question.
>
> I have an Accordion. In index 0 there is a datagrid that shows the records
> of the members and index 1 is a form. When you click on an item in the
> datagrid it throws you to the form with all the fields populated for the
> person you want to edit. Upon clicking save it saves all the information to
> the database correctly. Here comes my problem...
>
> I want it to refresh the data in the data grid and still be highlighted on
> the person you were editing (there are 321 members, I don't want the users
> to have to scroll through the list everytime to get to the last place they
> were). One tutorial said I could just recall the service and I then I made a
> function that looks up the last selected user and finds their index and
> tells the datagrid to scroll to that index. The problem with this method, is
> that the datagrid takes so long to refresh that the selected user has been
> selected again, and then when it finally finishes the refresh it overwrites
> the selected and starts back at the top of the grid with noone selected. I
> did check to make sure that the correct index is being found and that the
> scroll to and select work. It just isn't timing correctly. Instead of call
> refresh, refresh finish, then call select method and select, it's happening
> like call refresh, call select method and select, the it actually refreshes.
>
> Then I tried another method. I was thinking maybe it just takes to long to
> refresh data from a server and you are supposed to update both the server
> and the array collection at the same time, that this was would just be
> faster and maybe better all around. With the examples of this, I also don't
> have to worry about reselecting the last person I was on, because it just
> worked that way. Problem with this method is that the fields that are null
> are being fill in as blank in the array (database is still fine). I know
> this because I have a field in the table set up to show LastName
> (MaidenName) where the (MaidenName) only shows up if the field is not null
> but after update the field is showing up like LastName (). I have it set up
> so that I'm submitting the data to the array the same way as the database. I
> thought this would be find since the nulls are handled correctly in the
> database, but not so.
>
> Am I just trying to do this all the wrong way?
>
> Thank you,
>
> Sarah
>
>
>