When you add a new object to the dataProvider any chance you can add it with empty fields for the columns that do exist?  I’d imagine that it not having any values whatsoever could cause something like this.

 


From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Tim Blair
Sent: Saturday, May 07, 2005 10:22 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Dynamically poplulating an editable DataGrid

 

Evening all,

I'm having some issues with an editable data grid.  Basically it starts
of as an empty grid and the user can populate it by adding columns and
rows, but it doesn't appear to be working as I expect it to.

I can add columns using dg.addColumn() absolutely fine, and they are
displayed as expected.  However, when I add a new row (by adding a new
Object to the dataProvier array), I can't actually edit the field until
I've added another column.  Once I've done this, the new row can be
edited normally.  I can also "force" the row to be editable by tabbing
from one (already editable) row to a newly created one.

Additionally, after editing a cell, it appears that sometimes the
underlying data model is updated but the display is not updated.  For
example, using the code below, if I edit the one and only cell that's
automatically created and the move the focus somewhere else, the new
value isn't displayed (although I can get it back by re-editing the
cell).

Can anyone shed some light on this situation, or recommend another way
of going about things?

Thanks,

Tim.

PS. The code I'm testing with is as below:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml">

    <mx:Script>
    <![CDATA[
        // import the grid classes so we can use them
        import mx.controls.gridclasses.*;

        // the dataprovider to use for the grid
        var gripDP = [{col0:""}];

        // adds a new column to the data grid
        function gridAddColumn(colName:String) {
            // create a new column and give it an arbitrary name
            var newCol:DataGridColumn = new
DataGridColumn("col"+(myDataGrid.columnCount));
            // set some stuff
            newCol.headerText = colName;
            newCol.editable = true;
            newCol.sortable = false;
            // add the column
            myDataGrid.addColumn(newCol);
            myDataGrid.spaceColumnsEqually();
        }

        // adds a new row to the data grid
        function gridAddRow() {
            // we need to generate the object with the correct cells
            var newRow:Object = {};
            // get the current column names
            var aCols:Array = myDataGrid.columnNames;
            // loop through the column names and create an empty cell
item for each
            for (var i = 0; i < aCols.length; i++) { newRow[aCols[i]] =
""; }
            // push the new row to the dataprovider
            gripDP.push(newRow);
        }
    ]]>
    </mx:Script>

    <!-- holder for the grid and controls -->
    <mx:VBox width="500" height="300">
        <!-- the actual data grid -->
        <mx:DataGrid id="myDataGrid" dataProvider="{gripDP}"
editable="true" width="100%" height="240">
            <!-- by default there's already one row, which is the row
titles -->
           <mx:columns>
              <mx:Array>
                 <mx:DataGridColumn editable="true" sortable="false"
headerText="-" columnName="col0" />
              </mx:Array>
           </mx:columns>
        </mx:DataGrid>
       
        <!-- the buttons for controlling the datagrid -->
        <mx:HBox verticalAlign="bottom" width="100%">
            <mx:HBox width="100%">
                <mx:Label text="Col:" />
                <mx:TextInput id="newColName" width="80"
change="btnNewCol.enabled = newColName.text.length ? true : false" />
                <mx:Button id="btnNewCol" enabled="false" label="Add
Column" click="gridAddColumn(newColName.text); newColName.text = ''" />
            </mx:HBox>
            <mx:Button label="Add Row" click="gridAddRow()" />
        </mx:HBox>
    </mx:VBox>

</mx:Application>


--
-------------------------------------------------------
Badpen Tech - CF and web-tech: http://tech.badpen.com/
-------------------------------------------------------
    RAWNET LTD - independent digital media agency
    "We are big, we are funny and we are clever!"
     New site launched at http://www.rawnet.com/
-------------------------------------------------------
This message may contain information which is legally
privileged and/or confidential.  If you are not the
intended recipient, you are hereby notified that any
unauthorised disclosure, copying, distribution or use
of this information is strictly prohibited. Such
notification notwithstanding, any comments, opinions,
information or conclusions expressed in this message
are those of the originator, not of rawnet limited,
unless otherwise explicitly and independently indicated
by an authorised representative of rawnet limited.
-------------------------------------------------------



Yahoo! Groups Links

Reply via email to