AdvancedDataGrid highlights wrong row

Problem:

You have an AdvancedDataGrid which is highlighting the wrong row when you navigate using the mouse or keyboard.

Solution:

It is likely that you have put duplicate data in the dataProvider for your AdvancedDataGrid. It is illegal to put the same instance anywhere in the hierarchy of data that you assign to the dataProvider property. The regular DataGrid also has this limitation, which you can read about in the DataGrid highlights wrong row Solution. You can objects with identical data, but they must be different instances of the same object.

The only solution is to create unique objects for any data you want to display in an AdvancedDataGrid.

Further explanation, along with a SWF example and source code:

Example:

You can clearly see the incorrect behavior here. View Source is enabled and you can view this in its own page AdvancedDataGrid highlights wrong row example. Roll over the first child row and the AdvancedDataGrid will highlight the third child row:

Example SWF should load here if you have JavaScript enabled.

The data for this grid is defined here. Notice that obj1 is a child of both par1 and par2.

  1.         var array:Array = [];
  2.         var obj1:Object = {title:"The Ham", author:"Harold James"};
  3.         var obj2:Object = {title:"Hoodilly's", author:"Harold James"};
  4.         var obj3:Object = {title:"Kill-a-man-jaro", author:"Chuck Johnson"};
  5.  
  6.         var par1:Object = {category:"Fiction", children:[obj1, obj2]};
  7.         var par2:Object = {category:"Crime", children:[obj1, obj3]};
  8.         array.push(par1, par2);
  9.         dupData = new HierarchicalData(array);
  10.         dupData.childrenField = "children";

Explanation:

The explanation is identical to DataGrid. The AdvancedDataGrid indexes its data using a UID that is created for each row of data in the dataProvider. This code is actually in the HierarchicalCollectionView class which AdvancedDataGrid uses to manage its hierarchical data and present a view of the data to the user. The HierarchicalCollectionView gets the UID for each row by calling UIDUtil.getUID(item:Object). The UID returned is a String. See the entry on UIDUtil for more information on the generation method. This method will return the same UID when it is passed the same object.

HierarchicalCollectionView stores open nodes by UID in the openNodes property which is publicly accessible. It also stores the parents of nodes in an internal property (also defined as an Object which you can access through public function getParentItem(node:Object):*. This method converts the node:Object into a UID using UIDUtil and then looks up the parent in its internal property.

The situation is also similar when you try to highlight a row in the AdvancedDataGrid.