Re: [flexcoders] Re: FilterFunction creating duplicate items in the list
Hi All, I think I am able to solve the problem. The issue was that at every updates I was modifying the dataprovider which was cast as array collection. Once filter is applied the arraycollection keeps only the filtered rooms. So, even though a room might be present in the unfiltered source array, it will get added to the dataprovider if it was not present in the filtered dataprovider. To remove this, I have changed my update code to change the underlying array rather than modifying the arraycollection. Thanks, Rohit On Tue, Jun 2, 2009 at 8:50 AM, Tim Hoff timh...@aol.com wrote: I update the corresponding item in the dataprovider using setItemAt. (I typecast dataprovider as Arraycollection). Recently I added some filters to the room list using filterfunction. As soon as I start applying filters, I see few items getting duplicated in the list. Some items exist with old values as well as new values. Ok, so your indexes are not synchronized; returned data is getting set on the wrong items. How are you determining the correct index when using setItemAt()? If you're storing the position index when the ArrayCollection is un-filtered, and then filtering, the old index may not be the same as the new index in the filtered ArrayCollection. You can loop through the ArrayCollection and check the item's id field against the updated return item: * public * *function* getRoomResult( newRoomVO : RoomVO ) : *void *{ * for* *each* ( *var* oldRoomVO : RoomVO *in* rooms ) { * if* ( newRoomVO.id == oldRoomVO.id ) { rooms.setItemAt( newRoomVO, getItemIndex( oldRoomVO ) ); * return*; } } } However, this wouldn't update any items that were not included in the ArrayCollection, because of a filter. Updating the source Array itself would also do the trick. But, you would have to re-cast the ArrayCollection after an update. Just a few thoughts, -TH --- In flexcoders@yahoogroups.com, Tim Hoff timh...@... wrote: Sounds like your itemRenderer might not be clearing out old data correctly. Check out Question 2 in Amy's FAQ: http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf -TH --- In flexcoders@yahoogroups.com, Rohit Sharma rohit.sharma1982@ wrote: Hi All, I am stuck up with this problem. Please provide some insight into it. I have a list component which shows all the game rooms currently existing. As soon as some property of the room changes, I update the corresponding item in the dataprovider using setItemAt. (I typecast dataprovider as Arraycollection). Recently I added some filters to the room list using filterfunction. As soon as I start applying filters, I see few items getting duplicated in the list. Some items exist with old values as well as new values. I also tried making the filtering and updating actions mutually exclusive using flags hoping that two different actions taking place on the same data might cause duplication of items. But the duplication is still taking place. In fact I tried using itemUpdate() also in place of setItemAt but the problem still persists. I have also tried modifying only the source array during updates because the filtering takes place only on the ArrayCollection and not on the source array but this also failed. Any inputs will be appreciated. Thanks, Rohit
[flexcoders] Re: FilterFunction creating duplicate items in the list
I update the corresponding item in the dataprovider using setItemAt. (I typecast dataprovider as Arraycollection). Recently I added some filters to the room list using filterfunction. As soon as I start applying filters, I see few items getting duplicated in the list. Some items exist with old values as well as new values. Ok, so your indexes are not synchronized; returned data is getting set on the wrong items. How are you determining the correct index when using setItemAt()? If you're storing the position index when the ArrayCollection is un-filtered, and then filtering, the old index may not be the same as the new index in the filtered ArrayCollection. You can loop through the ArrayCollection and check the item's id field against the updated return item: public function getRoomResult( newRoomVO : RoomVO ) : void { for each ( var oldRoomVO : RoomVO in rooms ) { if ( newRoomVO.id == oldRoomVO.id ) { rooms.setItemAt( newRoomVO, getItemIndex( oldRoomVO ) ); return; } } } However, this wouldn't update any items that were not included in the ArrayCollection, because of a filter. Updating the source Array itself would also do the trick. But, you would have to re-cast the ArrayCollection after an update. Just a few thoughts, -TH --- In flexcoders@yahoogroups.com, Tim Hoff timh...@... wrote: Sounds like your itemRenderer might not be clearing out old data correctly. Check out Question 2 in Amy's FAQ: http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf -TH --- In flexcoders@yahoogroups.com, Rohit Sharma rohit.sharma1982@ wrote: Hi All, I am stuck up with this problem. Please provide some insight into it. I have a list component which shows all the game rooms currently existing. As soon as some property of the room changes, I update the corresponding item in the dataprovider using setItemAt. (I typecast dataprovider as Arraycollection). Recently I added some filters to the room list using filterfunction. As soon as I start applying filters, I see few items getting duplicated in the list. Some items exist with old values as well as new values. I also tried making the filtering and updating actions mutually exclusive using flags hoping that two different actions taking place on the same data might cause duplication of items. But the duplication is still taking place. In fact I tried using itemUpdate() also in place of setItemAt but the problem still persists. I have also tried modifying only the source array during updates because the filtering takes place only on the ArrayCollection and not on the source array but this also failed. Any inputs will be appreciated. Thanks, Rohit
[flexcoders] Re: FilterFunction creating duplicate items in the list
Sounds like your itemRenderer might not be clearing out old data correctly. Check out Question 2 in Amy's FAQ: http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf -TH --- In flexcoders@yahoogroups.com, Rohit Sharma rohit.sharma1...@... wrote: Hi All, I am stuck up with this problem. Please provide some insight into it. I have a list component which shows all the game rooms currently existing. As soon as some property of the room changes, I update the corresponding item in the dataprovider using setItemAt. (I typecast dataprovider as Arraycollection). Recently I added some filters to the room list using filterfunction. As soon as I start applying filters, I see few items getting duplicated in the list. Some items exist with old values as well as new values. I also tried making the filtering and updating actions mutually exclusive using flags hoping that two different actions taking place on the same data might cause duplication of items. But the duplication is still taking place. In fact I tried using itemUpdate() also in place of setItemAt but the problem still persists. I have also tried modifying only the source array during updates because the filtering takes place only on the ArrayCollection and not on the source array but this also failed. Any inputs will be appreciated. Thanks, Rohit