Re: [flexcoders] Re: Reuse a LabelFunction

2010-04-19 Thread Angelo Anolin


Thank you Alex and Amy for clarification.

Angelo



From: Alex Harui 
To: "flexcoders@yahoogroups.com" 
Sent: Fri, 16 April, 2010 22:51:20
Subject: Re: [flexcoders] Re: Reuse a LabelFunction

  
Amy is saying you could write your function like this:

private function labelFunctionTest( itm:Object, col:DataGridColumn) :String 
{
return df.format(itm[ col.dataField] );
}

Which is correct and probably the easiest way to go.  If you want to subclass 
you would do something like this:

 public class AngeloDataGridColum n extends DataGridColumn
 {
 public function AngeloDataGridColum n()
 {
 labelFunction = labelFunctionTest;
 }

 private function labelFunctionTest( item:Object, col:DataGridColumn) 
:String
 {
 return owner.document. df.format( item[dataField] );
 }
 }

By subclassing you don’t have to assign the labelFunctions to the columns that 
need them.

On 4/16/10 2:12 PM, "Angelo Anolin"  wrote:



>> 
>> 
>>   
>
>Hi Alex,
>> 
>>Appreciate if you could show a little example.
>> 
>>Thanks.
>> 
>>Angelo
>
>

From:Alex Harui 
>To: "flexcod...@yahoogro ups.com" 
>Sent: Fri, 16 April, 2010 12:29:57
>Subject: Re: [flexcoders] Re: Reuse a LabelFunction
>
>>  
>If it were me, I would subclass DataGridColumn and add the labelfunction to 
>the subclass.  Then it has the DGC’s context like dataField to work with.
>
>
>>On 4/16/10 7:40 AM, "valdhor"  wrote:
>
>
>
>>>> 
>>>> 
>>>>   
>>
>>>>If it were me, I would use an item renderer.
>>
>>>>--- In flexcod...@yahoogro ups.com <mailto:flexcoders% 40yahoogroups. com 
>>>><mailto:flexcoders% 40yahoogroups. com> > , Angelo Anolin >>>...> wrote:
>>>>>
>>>>> Hi Amy,
>>>>> 
>>>>> But as you can see in the function, I am specifying the Datafieldname 
>>>>> from the object which was passed.
>>>>> 
>>>>> How can I make it more generic so that I can re-use it in other datagrid 
>>>>> columns?  I hope you could provide some samples. thanks.
>>>>> 
>>>>> Angelo
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>>  _ _ __
>>>>> From: Amy 
>>>>> To: flexcod...@yahoogro ups.com <mailto:flexcoders% 40yahoogroups. com 
>>>>> <mailto:flexcoders% 40yahoogroups. com> > 
>>>>> Sent: Fri, 19 March, 2010 9:13:38
>>>>> Subject: [flexcoders] Re: Reuse a LabelFunction
>>>>> 
>>>>> Â  
>>>>> 
>>>>> 
>>>>> --- In flexcod...@yahoogro ups.com, Angelo Anolin  
>>>>> wrote:
>>>>> >
>>>>> > Hi FlexCoders,
>>>>> > 
>>>>> > I have created a labelfunction which I use in my datagrid to format the 
>>>>> > display value.
>>>>> > 
>>>>> > 
>>>>> > 
>>>>> > And this is the AS function
>>>>> > private function labelFunctionTest( itm:Object, col:DataGridColumn) 
>>>>> > :String
>>>>> > {
>>>>> > Â Â Â  return df.format(itm. DataFieldNamefor Col1);
>>>>> > }
>>>>> > 
>>>>> > Is there a way so that I could reuse the same label function to other 
>>>>> > datagrid columns?  As you can see from the script above, I am only 
>>>>> > using the function to Col1 for the datagrid.  How would I be able to 
>>>>> > specify the datafield if I am going to reuse the same with other 
>>>>> > datagrid columns?
>>>>> 
>>>>> That is what the DataGridColumn parameter is for. Look at its dataField 
>>>>> property.
>>>>> 
>>>>> HTH;
>>>>> 
>>>>> Amy
>>>>>
>>
>>>> 
>>>>   
>>
>>
>>
-- 
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs. adobe.com/ aharui
 
 


  

Re: [flexcoders] Re: Reuse a LabelFunction

2010-04-16 Thread Alex Harui
Amy is saying you could write your function like this:

private function labelFunctionTest( itm:Object, col:DataGridColumn) :String
{
return df.format(itm[col.dataField]);
}

Which is correct and probably the easiest way to go.  If you want to subclass 
you would do something like this:

 public class AngeloDataGridColumn extends DataGridColumn
 {
 public function AngeloDataGridColumn()
 {
 labelFunction = labelFunctionTest;
 }

 private function labelFunctionTest(item:Object, col:DataGridColumn):String
 {
 return owner.document.df.format(item[dataField]);
 }
 }

By subclassing you don’t have to assign the labelFunctions to the columns that 
need them.

On 4/16/10 2:12 PM, "Angelo Anolin"  wrote:






Hi Alex,

Appreciate if you could show a little example.

Thanks.

Angelo


From: Alex Harui 
To: "flexcoders@yahoogroups.com" 
Sent: Fri, 16 April, 2010 12:29:57
Subject: Re: [flexcoders] Re: Reuse a LabelFunction


If it were me, I would subclass DataGridColumn and add the labelfunction to the 
subclass.  Then it has the DGC’s context like dataField to work with.


On 4/16/10 7:40 AM, "valdhor"  wrote:






If it were me, I would use an item renderer.

--- In flexcod...@yahoogro ups.com <mailto:flexcoders% 40yahoogroups. com 
<mailto:flexcoders%40yahoogroups.com> > , Angelo Anolin  
wrote:
>
> Hi Amy,
>
> But as you can see in the function, I am specifying the Datafieldname from 
> the object which was passed.
>
> How can I make it more generic so that I can re-use it in other datagrid 
> columns?  I hope you could provide some samples. thanks.
>
> Angelo
>
>
>
>
>  _ _ __
> From: Amy 
> To: flexcod...@yahoogro ups.com <mailto:flexcoders% 40yahoogroups. com 
> <mailto:flexcoders%40yahoogroups.com> >
> Sent: Fri, 19 March, 2010 9:13:38
> Subject: [flexcoders] Re: Reuse a LabelFunction
>
> Â
>
>
> --- In flexcod...@yahoogro ups.com, Angelo Anolin  wrote:
> >
> > Hi FlexCoders,
> >
> > I have created a labelfunction which I use in my datagrid to format the 
> > display value.
> >
> > 
> >
> > And this is the AS function
> > private function labelFunctionTest( itm:Object, col:DataGridColumn) :String
> > {
> > Â Â Â  return df.format(itm. DataFieldNamefor Col1);
> > }
> >
> > Is there a way so that I could reuse the same label function to other 
> > datagrid columns?  As you can see from the script above, I am only using 
> > the function to Col1 for the datagrid.  How would I be able to specify the 
> > datafield if I am going to reuse the same with other datagrid columns?
>
> That is what the DataGridColumn parameter is for. Look at its dataField 
> property.
>
> HTH;
>
> Amy
>






--
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs.adobe.com/aharui


[flexcoders] Re: Reuse a LabelFunction

2010-04-16 Thread Amy


--- In flexcoders@yahoogroups.com, Angelo Anolin  wrote:
>
> Hi Amy,
> 
> But as you can see in the function, I am specifying the Datafieldname from 
> the object which was passed.
> 
> How can I make it more generic so that I can re-use it in other datagrid 
> columns?  I hope you could provide some samples. thanks.

By looking at the column value that gets passed into your function and seeing 
what data field it's talking about.



Re: [flexcoders] Re: Reuse a LabelFunction

2010-04-16 Thread Angelo Anolin
Hi Alex,

Appreciate if you could show a little example.

Thanks.

Angelo





From: Alex Harui 
To: "flexcoders@yahoogroups.com" 
Sent: Fri, 16 April, 2010 12:29:57
Subject: Re: [flexcoders] Re: Reuse a LabelFunction

  
If it were me, I would subclass DataGridColumn and add the labelfunction to the 
subclass.  Then it has the DGC’s context like dataField to work with.


On 4/16/10 7:40 AM, "valdhor"  wrote:



> 
> 
>   
>
>If it were me, I would use an item renderer.
>
>--- In flexcod...@yahoogro ups.com <mailto:flexcoders% 40yahoogroups. com> , 
>Angelo Anolin  wrote:
>>
>> Hi Amy,
>> 
>> But as you can see in the function, I am specifying the Datafieldname from 
>> the object which was passed.
>> 
>> How can I make it more generic so that I can re-use it in other datagrid 
>> columns?  I hope you could provide some samples. thanks.
>> 
>> Angelo
>> 
>> 
>> 
>> 
>>  _ _ __
>> From: Amy 
>> To: flexcod...@yahoogro ups.com <mailto:flexcoders% 40yahoogroups. com> 
>> Sent: Fri, 19 March, 2010 9:13:38
>> Subject: [flexcoders] Re: Reuse a LabelFunction
>> 
>> Â  
>> 
>> 
>> --- In flexcod...@yahoogro ups.com, Angelo Anolin  wrote:
>> >
>> > Hi FlexCoders,
>> > 
>> > I have created a labelfunction which I use in my datagrid to format the 
>> > display value.
>> > 
>> > 
>> > 
>> > And this is the AS function
>> > private function labelFunctionTest( itm:Object, col:DataGridColumn) :String
>> > {
>> > Â Â Â  return df.format(itm. DataFieldNamefor Col1);
>> > }
>> > 
>> > Is there a way so that I could reuse the same label function to other 
>> > datagrid columns?  As you can see from the script above, I am only using 
>> > the function to Col1 for the datagrid.  How would I be able to specify 
>> > the datafield if I am going to reuse the same with other datagrid columns?
>> 
>> That is what the DataGridColumn parameter is for. Look at its dataField 
>> property.
>> 
>> HTH;
>> 
>> Amy
>>
>
> 
>   
>
>
>
-- 
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs. adobe.com/ aharui




  

Re: [flexcoders] Re: Reuse a LabelFunction

2010-04-16 Thread Alex Harui
If it were me, I would subclass DataGridColumn and add the labelfunction to the 
subclass.  Then it has the DGC’s context like dataField to work with.


On 4/16/10 7:40 AM, "valdhor"  wrote:






If it were me, I would use an item renderer.

--- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , 
Angelo Anolin  wrote:
>
> Hi Amy,
>
> But as you can see in the function, I am specifying the Datafieldname from 
> the object which was passed.
>
> How can I make it more generic so that I can re-use it in other datagrid 
> columns?  I hope you could provide some samples. thanks.
>
> Angelo
>
>
>
>
> 
> From: Amy 
> To: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
> Sent: Fri, 19 March, 2010 9:13:38
> Subject: [flexcoders] Re: Reuse a LabelFunction
>
> Â
>
>
> --- In flexcod...@yahoogro ups.com, Angelo Anolin  wrote:
> >
> > Hi FlexCoders,
> >
> > I have created a labelfunction which I use in my datagrid to format the 
> > display value.
> >
> > 
> >
> > And this is the AS function
> > private function labelFunctionTest( itm:Object, col:DataGridColumn) :String
> > {
> > Â Â Â  return df.format(itm. DataFieldNamefor Col1);
> > }
> >
> > Is there a way so that I could reuse the same label function to other 
> > datagrid columns?  As you can see from the script above, I am only using 
> > the function to Col1 for the datagrid.  How would I be able to specify the 
> > datafield if I am going to reuse the same with other datagrid columns?
>
> That is what the DataGridColumn parameter is for. Look at its dataField 
> property.
>
> HTH;
>
> Amy
>






--
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs.adobe.com/aharui


[flexcoders] Re: Reuse a LabelFunction

2010-04-16 Thread valdhor
If it were me, I would use an item renderer.

--- In flexcoders@yahoogroups.com, Angelo Anolin  wrote:
>
> Hi Amy,
> 
> But as you can see in the function, I am specifying the Datafieldname from 
> the object which was passed.
> 
> How can I make it more generic so that I can re-use it in other datagrid 
> columns?  I hope you could provide some samples. thanks.
> 
> Angelo
> 
> 
> 
> 
> 
> From: Amy 
> To: flexcoders@yahoogroups.com
> Sent: Fri, 19 March, 2010 9:13:38
> Subject: [flexcoders] Re: Reuse a LabelFunction
> 
>   
> 
> 
> --- In flexcod...@yahoogro ups.com, Angelo Anolin  wrote:
> >
> > Hi FlexCoders,
> > 
> > I have created a labelfunction which I use in my datagrid to format the 
> > display value.
> > 
> > 
> > 
> > And this is the AS function
> > private function labelFunctionTest( itm:Object, col:DataGridColumn) :String
> > {
> >     return df.format(itm. DataFieldNamefor Col1);
> > }
> > 
> > Is there a way so that I could reuse the same label function to other 
> > datagrid columns?  As you can see from the script above, I am only using 
> > the function to Col1 for the datagrid.  How would I be able to specify the 
> > datafield if I am going to reuse the same with other datagrid columns?
> 
> That is what the DataGridColumn parameter is for. Look at its dataField 
> property.
> 
> HTH;
> 
> Amy
>




Re: [flexcoders] Re: Reuse a LabelFunction

2010-04-16 Thread Angelo Anolin
Hi Amy,

But as you can see in the function, I am specifying the Datafieldname from the 
object which was passed.

How can I make it more generic so that I can re-use it in other datagrid 
columns?  I hope you could provide some samples. thanks.

Angelo





From: Amy 
To: flexcoders@yahoogroups.com
Sent: Fri, 19 March, 2010 9:13:38
Subject: [flexcoders] Re: Reuse a LabelFunction

  


--- In flexcod...@yahoogro ups.com, Angelo Anolin  wrote:
>
> Hi FlexCoders,
> 
> I have created a labelfunction which I use in my datagrid to format the 
> display value.
> 
> 
> 
> And this is the AS function
> private function labelFunctionTest( itm:Object, col:DataGridColumn) :String
> {
>     return df.format(itm. DataFieldNamefor Col1);
> }
> 
> Is there a way so that I could reuse the same label function to other 
> datagrid columns?  As you can see from the script above, I am only using the 
> function to Col1 for the datagrid.  How would I be able to specify the 
> datafield if I am going to reuse the same with other datagrid columns?

That is what the DataGridColumn parameter is for. Look at its dataField 
property.

HTH;

Amy





  

[flexcoders] Re: Reuse a LabelFunction

2010-03-19 Thread Amy


--- In flexcoders@yahoogroups.com, Angelo Anolin  wrote:
>
> Hi FlexCoders,
> 
> I have created a labelfunction which I use in my datagrid to format the 
> display value.
> 
> 
> 
> And this is the AS function
> private function labelFunctionTest(itm:Object, col:DataGridColumn) :String
> {
>     return df.format(itm.DataFieldNameforCol1);
> }
> 
> Is there a way so that I could reuse the same label function to other 
> datagrid columns?  As you can see from the script above, I am only using the 
> function to Col1 for the datagrid.  How would I be able to specify the 
> datafield if I am going to reuse the same with other datagrid columns?

That is what the DataGridColumn parameter is for. Look at its dataField 
property.

HTH;

Amy



[flexcoders] Re: Reuse a LabelFunction

2010-03-18 Thread valdhor
You could write the Item Renderer as an MXML component or an
ActionScript class.

I have created a sample of both types that do the same thing. Sometimes
it easier to do it in MXML; Sometimes AS is the best way. With this
trivial example, both are about the same. Pick whichever way you like
the best.

DateRendererAS.as
package ItemRenderers
{
 import mx.controls.*;
 import mx.controls.dataGridClasses.DataGridListData;
 import mx.formatters.DateFormatter;

 public class DateRendererAS extends Label
 {
 private var myDateFormatter:DateFormatter = new DateFormatter();

 public function DateRendererAS()
 {
 super();
 myDateFormatter.formatString = "DD/MMM/";
 }

 override public function set data(value:Object):void
 {
 if(value != null)
 {
 super.data = value;
 text =
myDateFormatter.format(value[DataGridListData(listData).dataField]);
 }
 }
 }
}

DateRendererMXML.mxml

http://www.adobe.com/2006/mxml";>
 
 
 
 



And here is an application to try them out with (Change the itemRenderer
to DateRendererAS to try the AS version)

http://www.adobe.com/2006/mxml";
layout="vertical">
 
 
 
 
 
 
 
 
 
 




--- In flexcoders@yahoogroups.com, Angelo Anolin 
wrote:
>
> I do know a bit of using itemrenderer.. Inline that is..
>
> if you could post some example, I'd greatly appreciate it.
>
> would the itemrenderer be an as file or would it be inline as well?
>
> Thanks.
>
> Angelo
>
>
>
> 
> From: valdhor valdhorli...@...
> To: flexcoders@yahoogroups.com
> Sent: Wed, 17 March, 2010 14:41:19
> Subject: [flexcoders] Re: Reuse a LabelFunction
>
>
> Use an itemRenderer instead.
>
> If you need help creating one, let me know.
>
> --- In flexcod...@yahoogro ups.com, Angelo Anolin 
wrote:
> >
> > Hi FlexCoders,
> >
> > I have created a labelfunction which I use in my datagrid to format
the display value.
> >
> > 
> >
> > And this is the AS function
> > private function labelFunctionTest( itm:Object, col:DataGridColumn)
:String
> > {
> > return df.format(itm. DataFieldNamefor Col1);
> > }
> >
> > Is there a way so that I could reuse the same label function to
other datagrid columns?  As you can see from the script above, I am only
using the function to Col1 for the datagrid.  How would I be able to
specify the datafield if I am going to reuse the same with other
datagrid columns?
> >
> > Thanks.
> >
>



Re: [flexcoders] Re: Reuse a LabelFunction

2010-03-17 Thread Angelo Anolin
I do know a bit of using itemrenderer.. Inline that is.. 

if you could post some example, I'd greatly appreciate it.

would the itemrenderer be an as file or would it be inline as well?

Thanks.

Angelo




From: valdhor 
To: flexcoders@yahoogroups.com
Sent: Wed, 17 March, 2010 14:41:19
Subject: [flexcoders] Re: Reuse a LabelFunction

  
Use an itemRenderer instead.

If you need help creating one, let me know.

--- In flexcod...@yahoogro ups.com, Angelo Anolin  wrote:
>
> Hi FlexCoders,
> 
> I have created a labelfunction which I use in my datagrid to format the 
> display value.
> 
> 
> 
> And this is the AS function
> private function labelFunctionTest( itm:Object, col:DataGridColumn) :String
> {
> return df.format(itm. DataFieldNamefor Col1);
> }
> 
> Is there a way so that I could reuse the same label function to other 
> datagrid columns?  As you can see from the script above, I am only using the 
> function to Col1 for the datagrid.  How would I be able to specify the 
> datafield if I am going to reuse the same with other datagrid columns?
> 
> Thanks.
>


 


  

Re: [flexcoders] Re: Reuse a LabelFunction

2010-03-17 Thread Angelo Anolin
Ho would I be able to specify other dataField based from your example?

Say in my datagrid, col1's datafield is COL1 and col2 is COL2.

Using the label function, I need to fully qualify the datafield name like:

df.format(item[col.COL1])

which in turn I could only use for COL1.

Since I have some datagrid where the same date formatting can be used, then 
perhaps re-using the same label function would be of good help.

Thanks.




From: Alex Harui 
To: "flexcoders@yahoogroups.com" 
Sent: Wed, 17 March, 2010 19:13:26
Subject: Re: [flexcoders] Re: Reuse a LabelFunction

  
Should be df.format(item[ col.dataField] )


On 3/17/10 1:41 PM, "valdhor"  wrote:



>> 
>> 
>>   
>
>>Use an itemRenderer instead.
>
>>If you need help creating one, let me know.
>
>>--- In flexcod...@yahoogro ups.com <mailto:flexcoders% 40yahoogroups. com> , 
>>Angelo Anolin  wrote:
>>>
>>> Hi FlexCoders,
>>> 
>>> I have created a labelfunction which I use in my datagrid to format the 
>>> display value.
>>> 
>>> 
>>> 
>>> And this is the AS function
>>> private function labelFunctionTest( itm:Object, col:DataGridColumn) :String
>>> {
>>> return df.format(itm. DataFieldNamefor Col1);
>>> }
>>> 
>>> Is there a way so that I could reuse the same label function to other 
>>> datagrid columns?  As you can see from the script above, I am only using 
>>> the function to Col1 for the datagrid.  How would I be able to specify the 
>>> datafield if I am going to reuse the same with other datagrid columns?
>>> 
>>> Thanks.
>>>
>
>> 
>>   
>
>
>
-- 
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs. adobe.com/ aharui
 
 


  

Re: [flexcoders] Re: Reuse a LabelFunction

2010-03-17 Thread Alex Harui
Should be df.format(item[col.dataField])


On 3/17/10 1:41 PM, "valdhor"  wrote:






Use an itemRenderer instead.

If you need help creating one, let me know.

--- In flexcoders@yahoogroups.com  , 
Angelo Anolin  wrote:
>
> Hi FlexCoders,
>
> I have created a labelfunction which I use in my datagrid to format the 
> display value.
>
> 
>
> And this is the AS function
> private function labelFunctionTest(itm:Object, col:DataGridColumn) :String
> {
> return df.format(itm.DataFieldNameforCol1);
> }
>
> Is there a way so that I could reuse the same label function to other 
> datagrid columns?  As you can see from the script above, I am only using the 
> function to Col1 for the datagrid.  How would I be able to specify the 
> datafield if I am going to reuse the same with other datagrid columns?
>
> Thanks.
>






--
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs.adobe.com/aharui


[flexcoders] Re: Reuse a LabelFunction

2010-03-17 Thread valdhor
Use an itemRenderer instead.

If you need help creating one, let me know.

--- In flexcoders@yahoogroups.com, Angelo Anolin  wrote:
>
> Hi FlexCoders,
> 
> I have created a labelfunction which I use in my datagrid to format the 
> display value.
> 
> 
> 
> And this is the AS function
> private function labelFunctionTest(itm:Object, col:DataGridColumn) :String
> {
>     return df.format(itm.DataFieldNameforCol1);
> }
> 
> Is there a way so that I could reuse the same label function to other 
> datagrid columns?  As you can see from the script above, I am only using the 
> function to Col1 for the datagrid.  How would I be able to specify the 
> datafield if I am going to reuse the same with other datagrid columns?
> 
> Thanks.
>