Tracy,

            Here is my code. If you don't mind can you help me out in resolving this issue. Thanks!

 

            <mx:DataGrid id="myDataGrid" width="100%" dataProvider="{schedAdj_do}" textAlign="left" height="250" headerHeight="50" editable="true" cellEdit="updateData(event)">

                <mx:columns>

                          <mx:Array>

                            <mx:DataGridColumn headerText="#" columnName="adj_num" width="50" editable="false" textAlign="left"/>

                            <mx:DataGridColumn headerText="Type" columnName="adj_type" width="100" />

                            <mx:DataGridColumn headerText="Category" columnName="adj_category" width="150" />

                            <mx:DataGridColumn headerText="Terms" columnName="adj_amt_terms_desc" width="200" />

                            <mx:DataGridColumn headerText="{rptappl}" columnName="adj_reporter_applied_flag" width="50" />

                            <mx:DataGridColumn headerText="Sign" columnName="adj_sign" width="75" textAlign="center" />

                            <mx:DataGridColumn headerText="Factor" columnName="adj_factor" width="100" textAlign="right"/>

                            <mx:DataGridColumn headerText="{ordappl}" columnName="adj_order_applied" width="75" textAlign="left" />

                          </mx:Array>

                </mx:columns>

              </mx:DataGrid>

           

            function updateData(event:Object)

            {

                        mx.controls.Alert.show("cellEdit event fired ");     

                        var colName:String= event.target.getColumnAt(event.columnIndex).columnName;

        var row:Number = event.itemIndex;

                var dataValue = event.target.getItemAt(row)[colName];

        //mx.controls.Alert.show("event.columnIndex :"+event.columnIndex+newline+"colName : "+colName+newline+"new value : "+event.target.getItemAt(row)[colName]);

                        myDataGrid.dataProvider.editField( event.columnIndex, colName, dataValue);

            }

 

Thanks!
Hari

-----Original Message-----
From:
flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Tracy Spratt
Sent: Monday, May 23, 2005 5:12 PM
To:
flexcoders@yahoogroups.com
Subject: RE: [flexcoders] creating row in datagrid at runtime

 

Calling addItem() on the dataGrid is actually calling it on the dataProvider and physically adding the line.

 

Now, that line is empty, the "item" would be undefined (null?), and NOTE THIS: editing a datagrid cell does not automatically update the datagrid.  You will need to use the editCell event to call editField() to update the dp with the entered data.  I bet your dataProvider has a line but it is empty.

 

Tracy

 


From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Doodi, Hari - BLS CTR
Sent: Monday, May 23, 2005 3:25 PM
To: 'flexcoders@yahoogroups.com'
Subject: RE: [flexcoders] creating row in datagrid at runtime

 

Hi,

            I would like to extend the scope of this thread by asking How to make this newly added row as a part of the dataprovider? What I mean is I am able to create a new row in datagrid by using your methodology. But when I try to access data in my POJO, I am getting nullpointer exception. That means, I think, the newly added row to grid is not truly added to dataprovider. Do I have to make any specific function call to make the newly added row attach to dataprovider? If this question is already discussed, please guide me with reference.

 

Thanks!
Hari

-----Original Message-----
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Tracy Spratt
Sent: Friday, May 20, 2005 4:51 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] creating row in datagrid at runtime

 

Here's a little mod that automatically adds the new row when you tab out of the last cell.  The doLater reminder solved an aggravating problem I was having!

 

<?xml version="1.0"?>

<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"

      xmlns="*">

<mx:Script><![CDATA[

     

   function checkOnNav(oEvent:Object):Void

   {

      var iItemIndex:Number;

      var iColumnIndex:Number;

      switch (oEvent.type)

      {

         case "cellFocusOut":

            iItemIndex = oEvent.itemIndex;

            iColumnIndex = oEvent.columnIndex

            if (iColumnIndex == oEvent.target.columnNames.length - 1

                     && iItemIndex == oEvent.target.length - 1 )  {                             //leaving the last row, last column

               oEvent.target.addItem();

               doLater(this,"focusLastRow",[oEvent])

            }

            break;

        

      }//switch (oEvent.type)

   }//checkOnNav

     

   private function focusLastRow(oEvent:Object):Void{

      var dg:mx.controls.DataGrid = oEvent.target;

      dg.setFocus();

      dg.focusedCell = {columnIndex: 0, itemIndex: dg.dataProvider.length-1};

   }//setFocusNextLine

  

]]></mx:Script>

   <mx:DataGrid id="grid" editable="true"

         cellFocusOut="checkOnNav(event)">

      <mx:dataProvider>

         <mx:Array>

            <mx:Object name="manish" colour="red" />

            <mx:Object name="abdul" colour="blue" />

         </mx:Array>

      </mx:dataProvider>

   </mx:DataGrid>

 

</mx:Application>

 

-----Original Message-----
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Manish Jethani
Sent: Friday, May 20, 2005 9:50 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] creating row in datagrid at runtime

 

On 5/19/05, shettyaditsathish <[EMAIL PROTECTED]> wrote:

> i need to create a row in an existing datagrid on an event and show the

> the 1st column of the newly created row in editable mode.

 

<?xml version="1.0"?>

<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"

  xmlns="*">

  <mx:Script>

    function enterNewRow():Void

    {

      grid.addItem();

      focusNewRow();

      doLater(this, "focusNewRow");

    }

    function focusNewRow():Void

    {

      grid.setFocus();

      grid.focusedCell = {columnIndex: 0, itemIndex:

grid.dataProvider.length-1};

    }

  </mx:Script>

  <mx:DataGrid id="grid" editable="true">

    <mx:dataProvider>

      <mx:Array>

        <mx:Object name="manish" colour="red" />

        <mx:Object name="abdul" colour="blue" />

      </mx:Array>

    </mx:dataProvider>

  </mx:DataGrid>

  <mx:Button label="Enter New Row" click="enterNewRow()" />

</mx:Application>

 

Note:

 

 1.  grid.addItem() will add a blank row

 2.  call focusNewRow() in the next frame using doLater()

 

 

 

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/

 

 

 

 

 

 



Yahoo! Groups Links

Attachment: saveGrid.mxml
Description: Binary data

Reply via email to