You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by mark goldin <ma...@gmail.com> on 2015/04/01 10:09:56 UTC

Datagrid custom renderer based on filtered ArrayCollection

I am trying to come up with the following solution.
My datagrid's data has a few fields that would filter an ArrayCollection to
a single element.
That single element has a Bitmap data to show an image in a column.
Here is some relevant code:
private var _ArrayCol:ArrayCollection = new ArrayCollection();
override public function set data(value:Object):void
{
super.data = value;
if (data)
{
_ArrayCol.source = someGlobalArray.source;
_ArrayCol.filterFunction = filterIcon;
_ArrayCol.refresh();
if (_ArrayCol.length == 1)
{
image = new Bitmap(_ArrayCol[0].Icon);
}
}
}
private function filterIcon(item:Object):Boolean
{
if (item.CategoryID == data.Category && item.ModeID == data.Mode &&
item.Importance == data.Importance)
{
return true;
}
else
return false;
}

Currently I have data just for a few rows. So, initially I see icons in
these rows, but once I start scrolling they disappear. I understand that my
solution is not truly data driven. Question is what am I doing wrong?

Thanks

Re: Datagrid custom renderer based on filtered ArrayCollection

Posted by Evyatar Ben Halevi-Arbib <ev...@gmail.com>.
Hey,

I suggest creating new ArrayCollection instance in your set data function
as follows -
_ArrayCol = new ArrayCollection(someGlobalArray.source);

On the other hand, I don't really understand what you are trying to do here.
The item-renderer should get as data a single object (instance of an item
from the externally filtered collection).

You can try the solution I first suggested and if it doesn't help, explain
more about what you are trying to do.

Good luck,
Evyatar

On Wed, Apr 1, 2015 at 11:09 AM, mark goldin <ma...@gmail.com> wrote:

> I am trying to come up with the following solution.
> My datagrid's data has a few fields that would filter an ArrayCollection to
> a single element.
> That single element has a Bitmap data to show an image in a column.
> Here is some relevant code:
> private var _ArrayCol:ArrayCollection = new ArrayCollection();
> override public function set data(value:Object):void
> {
> super.data = value;
> if (data)
> {
> _ArrayCol.source = someGlobalArray.source;
> _ArrayCol.filterFunction = filterIcon;
> _ArrayCol.refresh();
> if (_ArrayCol.length == 1)
> {
> image = new Bitmap(_ArrayCol[0].Icon);
> }
> }
> }
> private function filterIcon(item:Object):Boolean
> {
> if (item.CategoryID == data.Category && item.ModeID == data.Mode &&
> item.Importance == data.Importance)
> {
> return true;
> }
> else
> return false;
> }
>
> Currently I have data just for a few rows. So, initially I see icons in
> these rows, but once I start scrolling they disappear. I understand that my
> solution is not truly data driven. Question is what am I doing wrong?
>
> Thanks
>