View Full Version : how to prevent datagrid from refreshing
magquatre
08-10-2007, 10:52 PM
How do i prevent my DataGrid to refresh and deselect the users selection after i update the datagrid's dataProvider?
I have a DataGrid where the dataProvider is being updated on an interval. The problem is that if there are many entries in the DataGrid, the refresh will cause the dataGrid scrollbar to reset to the top. Is there anyway to capture the event of the dataProvider being changed? or to capture the event that the datagrid gets refreshed?
Thank you
magquatre
08-11-2007, 04:58 PM
I've made some progress.
Although it is a hack i have been able to store the
"verticalScrollPosition, selectedItems, selectedItem, selectedIndices, selectedIndex" public properties of the Datagrid before i update the dataProvider.
I then restore these old values into the datagrid's properties and it does the right thing.
To make this successful i have to determine how to capture the event that either 1) the datagrid gets rerendered or 2) the datagrid's dataProvider gets changed.
any ideas?
right now i have a second timed event that restores the properties, while stress testing the delay it appears that it can only handle at least a 56ms delay after i restore the values into the dataGrid
Any shorter interval and the datagrid starts to get very buggy.
magquatre
08-11-2007, 05:29 PM
I found the event.
my_datagrid.addEventListener(FlexEvent.UPDATE_COMP LETE, _restoregrid);
where _restoregrid() is the function that restores the properties to my_datagrid
FlexBuilder's autocode-completion has a bug. It lists the event "Event.UPDATE_COMPLETE", which does not exist and causes the compiler to give an error. The only work around is to put FlexEvent.UPDATE_COMPLETE in its place.
This is a partial solution because there is a noticeable delay between the dataProvider getting reset and the _restoregrid() method being called.
magquatre
08-12-2007, 04:02 PM
Sorting: Apparently the recommended way to sort a datagrid is to sort the underlying dataProvider. But this can cause some unwanted effects. There is a workaround albeit a hack.
To restore the sorting selection the user made, first you have to create a handler for the DataGridEvent.HEADER_RELEASE event that will store the event.columnIndex property in memory.
my_datagrid.addEventListener(DataGridEvent.HEADER_ RELEASE, _store_column_sort);
...
private function _store_column_sort(event:DataGridEvent):void
{
grid_sorted_column_index = event.columnIndex;column_index = event.columnIndex
}
then in your _restoregrid function you have to dispatch a new a HEADER_RELEASE event to programmatically perform the sort on the stored column index:
private function _restoregrid(event:Event):void
{
...
my_datagrid.dispatchEvent(new DataGridEvent(DataGridEvent.HEADER_RELEASE, false, false, grid_sorted_column_index, null,0,null,null,0));
...
}
word of warning however, dispatching a HEADER_RELEASE event inside the function handler for the UPDATE_COMPLETE event will cause flex to go in an infinite loop. The internals of the header_release event will dispatch an update_complete event and cause your UPDATE_COMPLETE handler to loop forever. However with some simple binary logic IE:
if(counter = 0) {dont dispatch header_release; counter = 1;}
else {dispatch header_release; counter = 0;}
It should work fine. You just have to be sure to set the counter variable to 1 somewhere in the store_column_sort() function
dragonslayer300814
07-22-2008, 06:20 PM
I am having the same problem, but I have about thirty different grids. I can save all of the state information except the sorting b/c I'm not using a dataGridEvent? I'm just using the dataGrid itself. Before the data is saved I save the datagrid status then restore it immediately after. So only one dataGrid is updated at a time. Is there any way I can save the way the columns are sorted from the dataGrid itself?:confused:
NOCer
07-22-2008, 06:37 PM
have you guys tried making your data notbindable?
im pretty sure this will stop your datagrids from being updated anytime there is new data
then you can update it at your leisure
is that what you wanted to do?
dragonslayer300814
07-22-2008, 07:33 PM
I am updating the data in all the grids every 15 seconds. I'm using xml data and I just set the dataprovider during every refresh. The data isn't binded, well I mean I don't use [Bindable] anywhere. I am trying to find a way to save the sort before it is refreshed, and then restore that afterwards. I can do everything else, but the sort. =/
dragonslayer300814
07-23-2008, 07:51 PM
I got it working! Stupid how Flex provides functions for complex things, but if it's something simple like this, you are on your own. Anyways, it's a love/hate relationship w/ me and Flex.:cool:
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.