I am trying to use a Custom Date Cell Renderer which goes in edit mode
only when cell gains focus on it. Otherwise a label displays formatted
Date value.

Following is the code for the DateRenderer :-

import mx.core.UIComponent
import mx.core.UIObject
import mx.controls.DateField
import mx.controls.Label
import mx.controls.Alert
import mx.formatters.DateFormatter

class common.control.DateRenderer extends UIComponent{
        var dateObj:DateField;
        var label:Label;
        var dateFormat: DateFormatter;
        var listOwner : MovieClip;
        var getDataLabel : Function;
        var getCellIndex : Function;
        var __value;
        
        public function DateRenderer(){
                dateFormat = new DateFormatter();
                dateFormat.formatString="MM-DD-YYYY";
                this.addEventListener("focusIn", this);
                this.addEventListener("focusOut", this);
        }

        function createChildren(Void) : Void{
                super.createChildren();
                createClassObject( Label, "label", 1, {owner:this});
                label.width=80;
        }
        
        //Display date field for editing on focus.
        function focusIn() : Void {     
                createClassObject( DateField, "dateObj", 2, {owner:this});
                dateObj.width=80;
                dateObj.dateFormatter = this.formatDate;
                dateObj.selectedDate = __value;
                dateObj.addEventListener("change", this);               
                label.visible = false;
                dateObj.visible = true;
        }

         //Remove date field and make label visible again.
        function focusOut() : Void {            
                dateObj.visible = false;
                label.visible = true;
                destroyObject("dateObj");
        }

        //Format function
        function formatDate(itemDate){
                return dateFormat.format(itemDate);
        }
        
        function setValue( str:String, item:Object, sel:Boolean ) : Void{
                if(item != undefined){
                        label.text= formatDate( item[getDataLabel()]);
                        __value =  item[getDataLabel()];
                        label.visible = true;
                }
        }

        function getValue() : String {          
                return __value;
        }

        function getPreferredWidth(Void) : Number{
                return 80;
        }
        
        function getPreferredHeight(Void) : Number{
                return 30;
        }
        
        function change() {
                listOwner.editField(getCellIndex().itemIndex,
                        getDataLabel(), dateObj.selectedDate);
                __value = dateObj.selectedDate;
           
          // Fire Cell edit event for the DataGrid on date change
                listOwner.dispatchEvent({type:"cellEdit",
columnIndex:getCellIndex().columnIndex,
itemIndex:getCellIndex().itemIndex});
        }
        
}

Intially label displays the formatted date. But on clicking on the
cell default editor(textfield) is displayed. Can somebody please help
on what could be causing this problem.

Can i create my own custom editor just like the default text editor?

Thanks in advance,
Pradeep




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to