Hello all,

I've been trying to implement an e-ordering cart that
contains a datagrid with the selected products.

The idea was to have the quantity displayed in one of the
columns. If that cell is clicked, a NumericStepper should
appear using the cellrenderer method.

I've tried to implement this but stumbled onto 2 problems:
- The NumericStepper is visible after initialisation.
  If it is clicked on and then clicked somewhere else
  it shows how it should show in the first place.
  Any idea how to fix this ?
- If you press one of the arrows in the numericstepper, it
  seems to lose focus and the numericstepper disappears.
  This should only occur when pressed outside of the cell.

If someone could help me with this I'd be very gratefull.

Thanks in advance,

Max Westen.

----------------------------------------------------------------------
----------------
                                                                                
        
        Test1.mxml
----------------------------------------------------------------------
----------------
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"; 
xmlns="*"
    pageTitle="test e-ordering">

<mx:Script>
<![CDATA[
        var items = [   {nr:'001', naam:'Data1', prijs:100, aantal:10
},
                                                                {nr:'002', naam:
'Data2', prijs:200, aantal:120},
                                                                {nr:'003', naam:
'Data3', prijs:300, aantal:100}];       ]]>
</mx:Script>

        <mx:Form label="Winkelwagentje">
           <mx:DataGrid id="dg_winkelwagen" dataProvider="{items}" 
editable="true">
            <mx:columns>
              <mx:Array>
               <mx:DataGridColumn headerText="Prod. nr."        
columnName="nr"                                 editable="false" />
               <mx:DataGridColumn headerText="Name"                     
columnName="artikel"            editable="false" />
               <mx:DataGridColumn headerText="Price"                    
columnName="prijs"                      textAlign="right" marginRight="4" 
editable="false"/>
               <mx:DataGridColumn headerText="Quantity"         
columnName="aantal"             textAlign="right" marginRight="4" 
editable="true" cellRenderer="NumericRenderer" />
              </mx:Array>
            </mx:columns>
           </mx:DataGrid>
        </mx:Form>
</mx:Application>

----------------------------------------------------------------------
----------------
                                                                                
        
                NumericRenderer.as
----------------------------------------------------------------------
----------------
import mx.core.UIComponent
import mx.controls.NumericStepper
import mx.controls.Label;


class NumericRenderer extends UIComponent
{
        private var stepper:NumericStepper;
        //var stepper : MovieClip;
        var myLabel : MovieClip;
        var isCellEditor : Boolean = true;
        var listOwner : MovieClip; // the reference we receive to the 
list
        var getCellIndex : Function; // the function we receive from the 
list
        var     getDataLabel : Function; // the function we receive from 
the list
        var editing : Boolean = false;

        function createChildren(Void):Void
        {
                stepper = mx.controls.
NumericStepper(createObject("NumericStepper", "stepper", 1, 
{styleName:this, owner:this}));
                myLabel = createClassObject(Label, "myLabel", 2, 
{styleName:this, owner:this});
                stepper.minimum = 1;
                stepper.maximum = 200;

                this.addEventListener("focusIn", this);
                stepper.addEventListener("change", this);
                stepper.addEventListener("focusOut", this);
                stepper.visible = false;
                myLabel.visible = true;
        }

        function layoutChildren() {
                stepper.setSize(layoutWidth, layoutHeight);
                myLabel.setSize(layoutWidth, layoutHeight);
        }

        function getValue(){
                return stepper.value;
        }

        function setValue(value, item:Object, sel:Boolean):Void
        {
        if (!editing) {
                        var v = item[getDataLabel()];
                        v = (v == null ? "" : item[getDataLabel()]);
                        stepper.value = v;
                        myLabel.text = v;
                }
        }

        function getPreferredHeight(Void) : Number
        {
                return stepper.getPreferredHeight();
        }

        function getPreferredWidth(Void) : Number
        {
                return stepper.getPreferredWidth();
        }

        function change() {
                myLabel.text = stepper.value;
        }

        function moveFocus(cell) {
                listOwner.focusedCell = cell;
        }

        function focusIn() {
                stepper.visible = true;
                myLabel.visible = false;
                editing = true;
                stepper.setFocus();
        }

        function focusOut() {
                listOwner.editField(getCellIndex().itemIndex, 
getDataLabel(), stepper.value);
                stepper.visible = false;
                myLabel.visible = true;
                editing = false;
        }

        function drawFocus() {
                super.drawFocus(false);
        }

}






------------------------ Yahoo! Groups Sponsor --------------------~--> 
Most low income households are not online. Help bridge the digital divide today!
http://us.click.yahoo.com/cd_AJB/QnQLAA/TtwFAA/nhFolB/TM
--------------------------------------------------------------------~-> 

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
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