this is a bit simplier example of reusable renderer/editor
 
package  com.theriabook.controls
{
 import mx.controls.DateField
 import mx.controls.dataGridClasses.DataGridListData;
 import mx.controls.listClasses.ListData;
 
 public class DateField extends mx.controls.DateField
 {
  private function checked (val : Object):Date {
   if (val is String)
    return new Date(Date.parse(val as String))
   else
    return val as Date
  }
 
  override public function set data(value:Object):void {
   if (listData && listData is DataGridListData)
    value[DataGridListData(listData).dataField] = checked(value[DataGridListData(listData).dataField]);
         else if (listData is ListData && ListData(listData).labelField in data)
    value[ListData(listData).labelField] = checked(value[ListData(listData).labelField]);
   super.data = "">  }
 }
}
 
 
The usage case:
                <mx:DataGridColumn dataField="EndEval" editable="true"  width="100"
                                      headerWordWrap="true" headerText="End Evaluation"
                                    rendererIsEditor="true" 
                                     itemRenderer="com.theriabook.controls.DateField"/>
 
Regards,
Anatole Tartakovsky


 
----- Original Message -----
Sent: Tuesday, September 19, 2006 11:30 AM
Subject: Re: [flexcomponents] subclassing DateField controls

I should say that I've got this (below) working OK so far (couple of tweeks needed)


the 3 things to do is
 - combine the dateField and dateFormatter controls
 - pass in the format string
and the tough bit
 - switch between using DataGridListData(listData) ... or not...(depending on how the control is used)


                <mx:DataGridColumn dataField="EndEval" editable="true"  width="100"
                                      headerWordWrap="true" headerText="End Evaluation"
                                    rendererIsEditor="true"
                                     editorDataField="selectedDate">
                         <mx:itemRenderer>
                          <mx:Component>
                          <mx:DateField editable="true" labelFunction="formatDate" parseFunction="myParseFunction">
                           <mx:DateFormatter id="dfconv" formatString="DD/MM/YYYY">
                            <mx:Script>
                                <![CDATA[
                                    private function formatDate(date:Date):String{
                                        return dfconv.format(date);
                                    }
                                   
                                    public function myParseFunction( inputString : String,
                                        formatString : String = "DD/MM/YYYY") : Date {
                                        if (inputString == "") {
                                            return null;
                                        }
                                       
                                        var year : Number = Number(inputString.substr(6,4));
                                        var month : Number = Number( inputString.substr(3,2)) - 1;
                                        var day : Number = Number(inputString.substr(0,2));
                                        var date : Date = new Date(year,month,day);
                                        return date;
                                    }      
                                ]]>
                            </mx:Script>                  
                           </mx:DateFormatter>   
                           </mx:DateField>
                          </mx:Component>
                         </mx:itemRenderer>                      
               </mx:DataGridColumn>


__._,_.___


SPONSORED LINKS
Software development tool Application development software Development software
Development outsourcing software Embedded software development

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___

Reply via email to