Re: [flexcoders] Re: How to have datagrids with different filterfunction for a single dataprovide

2007-02-09 Thread EECOLOR

This is possible if you use the class below. It extends ArrayCollection and
adds two methods:

addReflection(reflection:ArrayCollection)
removeReflection(reflection:ArrayCollection)

This class makes sure the reflections share the list (inner dataProvider) of
the main collection. If something changes in the list all child components
will be refreshed automatically.

This class ensures that more collections share the same data, this helps you
in the sence that you dont need to copy the collections if you want to use
different filters for different views.


Greetz Erik


package fly.flex.collections
{
import mx.collections.ArrayCollection;
import flash.utils.Dictionary;
import mx.events.CollectionEvent;
import mx.events.CollectionEventKind;
import mx.collections.IList;
import mx.binding.utils.BindingUtils;
import mx.binding.utils.ChangeWatcher;
import flash.utils.Timer;
import flash.events.TimerEvent;

public class ReflectorArrayCollection extends ArrayCollection
{
 private var _reflections:Dictionary;
 private var _timer:Timer;
 private var _reflectionsNeedRefresh_bool:Boolean;

 public function ReflectorArrayCollection(source:Array = null)
 {
  super(source);

  _reflections = new Dictionary(true);
  _timer = new Timer(0);
  _timer.addEventListener(TimerEvent.TIMER, _timerHandler);
 };

 private function _timerHandler(e:TimerEvent):void
 {
  if (_reflectionsNeedRefresh_bool)
  {
   _reflectionsNeedRefresh_bool = false;

   var obj:Object;
   var reflection:ArrayCollection;
   for (obj in _reflections)
   {
reflection = obj as ArrayCollection;
reflection.refresh();
   };
  };
 };

 private function _collectionChangeHandler(e:CollectionEvent):void
 {
  /*
   If we would refresh the reflections here they items would not yet
   be available. Apparently this handler is called too fast. A handler
outside of this class would work. To solve it we use a timer.
   */
  _reflectionsNeedRefresh_bool = true;
  _timer.start();
 };

 public function addReflection(reflection:ArrayCollection):void
 {
  _reflections[reflection] = BindingUtils.bindProperty(reflection, list,
this, list);
 };

 public function removeReflection(reflection:ArrayCollection):void
 {
  var watcher:ChangeWatcher = _reflections[reflection];
  watcher.unwatch();

  delete _reflections[reflection];
 };

 /*
  The list setter is overridden in order to make sure we allways have a
listener
  to the correct internal list.
 */
 override public function set list(value:IList):void
 {
  if (list)
  {
   list.removeEventListener(CollectionEvent.COLLECTION_CHANGE,
_collectionChangeHandler);
  };

  super.list = value;

  if (list)
  {
   list.addEventListener(CollectionEvent.COLLECTION_CHANGE,
_collectionChangeHandler);
  };
 };
};
};


RE: [flexcoders] Re: How to have datagrids with different filterfunction for a single dataprovide

2007-01-15 Thread Stembert Olivier \(BIL\)
I think Daniel wants to filter the rows.
I don't see any solution except to duplicate the original one...
 
Olivier



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of phipzkillah
Sent: Monday, January 15, 2007 10:56 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: How to have datagrids with different
filterfunction for a single dataprovide



Daniel,

I believe it's possible to do this with one array collection.

Set up 3 datagrids with the dataprovider set to your array collection
variable.

For each datagrid specify the columns you want to be displayed:

mx:columns
mx:Array mx:DataGridColumn dataField=@name
headerText=Name/ mx:DataGridColumn dataField=@total
headerText=Total/
/mx:Array
/mx:columns

That should to it...

Phil

--- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com
, Dan [EMAIL PROTECTED] wrote:

 Hi,
 
 I want to have 3 datagrids with the same dataprovider but show 
 different part of it according to the filterFunction? Is it possible? 
 Or i need to copy the arraycollection into three and each have to 
 update back the original one by the observe tag by adobe??? Anyone 
 has any idea? Thanks
 
 Daniel




 

-

An electronic message is not binding on its sender.

Any message referring to a binding engagement must be confirmed in
writing and duly signed.

-

 


-
An electronic message is not binding on its sender.
Any message referring to a binding engagement must be confirmed in writing and 
duly signed.
-