我正在尝试使用MXAdvancedDataGridItemRenderer为AdvancedDataGrid创建项呈示器。
当我将示例自定义项目渲染器(MXAdvancedDataGridItemRenderer)附加到AdvancedDataGrid中的分层数据时,项目渲染器不会正确渲染单元格。 如果未选择,则自定义渲染器将仅呈现为悬停(突出显示)状态。选择并悬停行后,自定义项呈示器将仅将单元格呈现为选中状态。
如何让自定义渲染器识别在突出显示行时应突出显示?
下图显示了此示例。选择第一行,鼠标在第二个单元格上。正如您所看到的那样,单元格被渲染为“已选中”而不是“悬停”。
这是一个示例应用程序:
<?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">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var data:ArrayCollection = new ArrayCollection([
{label:"Fruit", children:[
{label:"Apple", price:1.5},
{label:"Banana", price:2},
{label:"Orange", price:1.75}]},
{label:"Drink", children:[
{label:"Water", price:0.5},
{label:"Milk", price:2.25},
{label:"Juice", price:1.25}]}
]);
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:AdvancedDataGrid x="10" y="10" width="350" height="200" itemRenderer="TestItemRenderer">
<mx:dataProvider>
<mx:HierarchicalData source="{data}"/>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn headerText="Name" dataField="label"/>
<mx:AdvancedDataGridColumn headerText="Price" dataField="price"/>
</mx:columns>
</mx:AdvancedDataGrid>
</s:Application>
这是示例MXAdvancedDataGridItemRenderer:
<?xml version="1.0" encoding="utf-8"?>
<s:MXAdvancedDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
focusEnabled="true">
<s:Label id="lblData" top="0" left="0" right="0" bottom="0" text="{listData.label}" />
</s:MXAdvancedDataGridItemRenderer>
答案 0 :(得分:3)
您可能想尝试将add autoDrawBackground =“false”添加到MXAdvancedDataGridItemRenderer。我在使用ADG的“单格”选择模式时遇到了问题,这解决了这个问题。
<?xml version="1.0" encoding="utf-8"?>
<s:MXAdvancedDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
focusEnabled="true"
autoDrawBackground="false">
<s:Label id="lblData" top="0" left="0" right="0" bottom="0" text="{listData.label}" />
</s:MXAdvancedDataGridItemRenderer>
答案 1 :(得分:1)
试试这个(注意rollOverColor
):
<mx:AdvancedDataGrid x="10" y="10" width="350" height="200" rollOverColor="0xff0000" itemRenderer="TestItemRenderer">
<mx:dataProvider>
<mx:HierarchicalData source="{data}"/>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn headerText="Name" dataField="label"/>
<mx:AdvancedDataGridColumn headerText="Price" dataField="price"/>
</mx:columns>
</mx:AdvancedDataGrid>
干杯, 罗布
答案 2 :(得分:0)
您也可以通过为AdvancedDataGrid设置'Style'来实现此目的
AdvancedDataGrid {
textRollOverColor: #000000;
textSelectedColor: #FFFFFF;
disabledColor: #8E8E8E;
borderColor: #454545;
alternatingItemColors: #FFFFFF, #FCFCFC;
verticalGridLineColor: #F6F6F6;
color: #000000;
selectionColor: #A0B3BE;
rollOverColor: #DBE4E6;
borderStyle: none;
borderThickness: 0;
fontSize: 12;
headerColors: #DBE4E6, #DBE4E6;
selectionDisabledColor: #FFFFFF;
}