2 Replies Latest reply: Aug 10, 2011 12:53 AM by Gabriele Genta RSS

    Selection issue with editable Spark DataGrid

    Gabriele Genta

      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

      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

        • 1. Re: Selection issue with editable Spark DataGrid
          Darrell Loverin FormerEmployees

          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"
                         minWidth="955" minHeight="600"
                  <s:HorizontalLayout horizontalAlign="center" verticalAlign="middle"/>
                      import mx.collections.XMLListCollection;
                      import mx.events.FlexEvent;
                      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"/>

          • 2. Re: Selection issue with editable Spark DataGrid
            Gabriele Genta Community Member

            Thank you Darrell for your answer. I already had a workaround in place while waiting for someone to clarify the situation; since it is a known bug I will stick with it and wait for the new version.

            Thanks a lot,