Skip navigation
Gabriele Genta
Currently Being Moderated

Selection issue with editable Spark DataGrid

Aug 6, 2011 2:26 AM

Hi everyone,

I am evaluating the new Spark DataGrid and I'm having a very strange issue with the behavior of selection in an editable instance.

Here is my test application: (code here:

And here are the steps to reproduce the issue:

  1. select the very first cell at the top-left corner of the grid (the one with "Gabriele");
  2. click on it once more, the editor appears;
  3. now click on the cell just to the right of it (the one with "Genta").

You should see that editing ends as it supposed to do, but selection is placed on the third cell (the one with a 5 in it) instead on the one you clicked on. Playing a little with the grid you should see that this isn't the only case, but selection is really behaving randomly.

I am using SDK

I think this is a very basic usage case.. I can't believe this is not working properly, what am I missing?

Thanks a lot,


Gabriele Genta


Message was edited to add live example

  • Currently Being Moderated
    Aug 9, 2011 8:54 PM   in reply to Gabriele Genta

    Your running into a known bug,


    The  bug will be fixed in the Mega release. To work around the bug you can  create a custom editor and remove the  "dataGrid.validateNow();" call in


    Here's how I modified your example to workaround the bug:


    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx=""
                   minWidth="955" minHeight="600"
            <s:HorizontalLayout horizontalAlign="center" verticalAlign="middle"/>
                import mx.collections.XMLListCollection;
                protected function application1_creationCompleteHandler(event:FlexEvent):void
                    testGrid.dataProvider = new XMLListCollection(testData.item);
            <fx:XML id="testData" xmlns="">
            <fx:Component className="MyDefaultEditor">
                            import mx.collections.ICollectionView;
                            import mx.collections.ISort;
                            override public function save():Boolean
                                if (!validate())
                                    return false;
                                var newData:Object = value;
                                var property:String = column.dataField;
                                var data:Object = data;
                                var typeInfo:String = "";
                                for each(var variable:XML in describeType(data).variable)
                                    if (property == variable.@name.toString())
                                        typeInfo = variable.@type.toString();
                                if (typeInfo == "String")
                                    if (!(newData is String))
                                        newData = newData.toString();
                                else if (typeInfo == "uint")
                                    if (!(newData is uint))
                                        newData = uint(newData);
                                else if (typeInfo == "int")
                                    if (!(newData is int))
                                        newData = int(newData);
                                else if (typeInfo == "Number")
                                    if (!(newData is Number))
                                        newData = Number(newData);
                                else if (typeInfo == "Boolean")
                                    if (!(newData is Boolean))
                                        var strNewData:String = newData.toString();
                                        if (strNewData)
                                            newData = (strNewData.toLowerCase() == "true") ? true : false;
                                if (property && data[property] !== newData)
                                    // If the data is sorted, turn off the sort for the edited data.
                                    var sort:ISort = null;
                                    if (dataGrid.dataProvider is ICollectionView)
                                        var dataProvider:ICollectionView = ICollectionView(dataGrid.dataProvider);
                                        if (dataProvider.sort)
                                            sort = dataProvider.sort;
                                            dataProvider.sort = null;
                                    var oldData:Object = data[property];
                                    data[property] = newData;
                                    dataGrid.dataProvider.itemUpdated(data, property, oldData, newData);
                                    // Restore the sort. The data will not be sorted due to this change.
                                    if (sort)
                                        ICollectionView(dataGrid.dataProvider).sort = sort;
                                return true;
        <s:DataGrid id="testGrid" width="100%" height="100%"
                    editable="true" selectionMode="singleCell"
                    itemEditor="{new ClassFactory(MyDefaultEditor)}">
                    <s:GridColumn headerText="Prova" dataField="cognome"/>
                    <s:GridColumn headerText="Prova1" dataField="nome"/>
                    <s:GridColumn headerText="Prova3" dataField="uhm"/>
                    <s:GridColumn headerText="Prova4" dataField="bene"/>

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points