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: http://www.playcalliope.com/flex/DataGridSelectionIssue.html (code here: https://gist.github.com/1129160)

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 4.5.1.21328.

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

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

    Your running into a known bug, https://bugs.adobe.com/jira/browse/SDK-30088.

     

    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  DataGridEditor.save().

     

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

     

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/mx"
                   minWidth="955" minHeight="600"
                   backgroundColor="#E7E7E7"
                   creationComplete="application1_creationCompleteHandler(event)">
        <s:layout>
            <s:HorizontalLayout horizontalAlign="center" verticalAlign="middle"/>
        </s:layout>
       
        <fx:Script>
            <![CDATA[
                import mx.collections.XMLListCollection;
                import mx.events.FlexEvent;
                protected function application1_creationCompleteHandler(event:FlexEvent):void
                {
                    testGrid.dataProvider = new XMLListCollection(testData.item);
                }
            ]]>
        </fx:Script>
       
        <fx:Declarations>
            <fx:XML id="testData" xmlns="">
                <items>
                    <item>
                        <id>1</id>
                        <cognome>Gabriele</cognome>
                        <nome>Genta</nome>
                        <uhm>5</uhm>
                        <bene>molto</bene>
                    </item>
                    <item>
                        <id>10</id>
                        <cognome>Pinco</cognome>
                        <nome>Pallino</nome>
                        <uhm>10</uhm>
                        <bene>poco</bene>
                    </item>
                </items>
            </fx:XML>
           
            <fx:Component className="MyDefaultEditor">
                <s:DefaultGridItemEditor>
                    <fx:Script>
                        <![CDATA[
                            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();
                                        break;
                                    }
                                }
                               
                                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;
                            }
                        ]]>
                    </fx:Script>               
                </s:DefaultGridItemEditor>
               
            </fx:Component>
        </fx:Declarations>
       
        <s:DataGrid id="testGrid" width="100%" height="100%"
                    editable="true" selectionMode="singleCell"
                    itemEditor="{new ClassFactory(MyDefaultEditor)}">
            <s:columns>
                <s:ArrayList>
                    <s:GridColumn headerText="Prova" dataField="cognome"/>
                    <s:GridColumn headerText="Prova1" dataField="nome"/>
                    <s:GridColumn headerText="Prova3" dataField="uhm"/>
                    <s:GridColumn headerText="Prova4" dataField="bene"/>
                </s:ArrayList>
            </s:columns>
        </s:DataGrid>
    </s:Application>

     
    |
    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