Flex DataGrid/DataProvider bug?

2019-07-23 16:40发布

问题:

Creating a datagrid and dataprovider, if the dataprovider contains 2 of the same value ({"A","A","B"}), when you hover over any of the rows containing "A" all rows containing "A" will also get highlighted.

Anyone else notice this issue?

回答1:

Whydna you are on the right track with the post you shared http://jonathanbranam.net/solutions/datagrid-highlights-wrong-row. The reason this is confusing flash/flex is that the datagrid uses equality to determine when it has found a match for a row. This could be fixed by patching the framework to use strict equality (===) but the better answer for now is to do as that post suggests and wrap your values in an object so that there is not risk of this issue. You will also see the same behavior if you added several identical objects, as the example at the link shows. Here is a working example to make sure you have what you need.

<mx:DataGrid id="dataGrid" dataProvider="{gridData}" creationComplete="init()">
    <mx:columns>
        <mx:DataGridColumn dataField="title" headerText="Title" />
    </mx:columns>
</mx:DataGrid>

<mx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;

        [Bindable] private var gridData:ArrayCollection;    

        protected function init():void
        {
            gridData = new ArrayCollection();

            for(var i:uint = 0; i < 10; i++)
            {
                gridData.addItem({title: "This is an item"});   
            }

        }

    ]]>
</mx:Script>