Rather than set a "fake" data field, it seems you could just provide a getter in the top object (the one that the grid knows about) that returns the value of the property from the related object?

i.e.

public function get relatedProp():String
{
   return this._relatedObj.prop;
}

Then set your grid column to use "relatedProp" as the data field. The advantage of this approach is that you will not have duplicate values in the system which could potentially get out of synch. But, this probably won't help any with your dynamically related objects. For that I am guessing you will have to do as Tracy suggested and translate to "display objects" in preprocessing. I am thinking you would need to use untyped objects, then set properties into them (as you are doing now), then set the column.dataField property to match the property name you set into the object you created.

hth
Scott

Scott Melby
Founder, Fast Lane Software LLC
http://www.fastlanesw.com
http://blog.fastlanesw.com



kallebertell wrote:
Thanks.
To complicate things further I have to be able add new columns
dynamically which are the same kind of "relational" columns.

For now I managed to solve it with a hack. I abandoned setting the actual relation object into the renderer, and instead just use the same object everywhere on the same row. I set a fake dataField property to a property which exists in the "X
object", and then just not use it for rendering but set the text I
want in the custom renderer.

Afaik. all sorting etc. works correctly now and no exceptions are
being thrown.

--- In flexcoders@yahoogroups.com, "Tracy Spratt" <[EMAIL PROTECTED]> wrote:
You could pre-process the different objects into a collection of display
objects.

Tracy

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of kallebertell
Sent: Friday, March 28, 2008 8:03 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Datagrid with different objects in each cell

I have a case of a datagrid where I have to fetch a value from different
objects depending on the column.

---X----A---B---C---D-
1--X1---A1--B1--C1--D1
2--X2---A2--B2--C2--D2
3--X3---A3--B3--C3--D3
4--X4---A4--B4--C4--D4

The datagrid's dataprovider is an ArrayCollection of objects of type X.

What I'm trying to do is showing relations between objects of type X to
types A, B, C and D.
These relations are objects themselves and have their own properties. It
is this relational property I want to display.

I've solved this by having special column which gets the object
(A,B,C,D) they're being relating to passed into them.
I then use a special renderer which overrides grabs the object it's
being related to (A,B,C or D) from its parent column;
and uses this info to pick out the correct (overriding set data)
relation object from the X object.

This all works fine, until I try to sort one of the special columns; and
I do need to be able to sort them.
I almost got it working by doing a custom sortCompareFunction in the
column, but then it fails on an exception, "Error: Find criteria must
contain at least one sort field value.", although it seemed to get the
sorting done.

Diving into the source it looks like it is a strong assumption (at least
in sorting) that each row in the datagrid is representing a property
from the same object,
which of course it isn't for me.

I thought I'd put a message here before continuing hacking away at this.

Anyone done something similar to this and is it possible to do this
elegantly?




Reply via email to