【发布时间】:2011-07-22 17:57:13
【问题描述】:
我有两个数据网格 1. OPTION GRID 和 2. ELECTION GRID。我在 ELECTION GRID 中使用 VBox 容器作为 itemRenderer,它由描述列中的 TextInput 组成。以下是示例 SWF。
每当在 OPTION GRID 中选中复选框时,我必须在所有行的第二个网格(ELECTION GRID)中添加一个带有描述值的相应文本输入。假设如果选择了两个复选框,我必须在第二个网格中添加两个文本输入,依此类推......这工作正常。但是,每当我编辑文本输入并向上或向下滚动时,该值就会在行之间折叠或消失。 我怀疑 itemRenderers 将在滚动时重新用于其他行。如何在 textinput 中保留编辑后的值?
以下是代码。
主要代码:
<mx:VBox width="100%" height="100%">
<mx:Label text="OPTION GRID :" fontSize="12" fontStyle="normal" fontThickness="15"/>
<components:CAEventDetailDataGrid width="100%" height="20%" dataProvider="{optionData}" allowMultipleSelection="true" optionSelected="onOptionSelection(event)">
<components:columns>
<mx:DataGridColumn dataField="selected" headerText="Select All" itemRenderer="renderer.CheckBoxItemRenderer" width="70" textAlign="center"/>
<mx:DataGridColumn dataField="optionId" headerText="Option" textAlign="left"/>
<mx:DataGridColumn dataField="option" headerText="Description" textAlign="left"/>
</components:columns>
</components:CAEventDetailDataGrid>
<mx:Label text="ELECTION GRID :" fontSize="12" fontStyle="normal" fontThickness="15"/>
<mx:DataGrid id="electionGrid" width="100%" height="30%" dataProvider="{electionSummary}" rowCount="3" verticalScrollPolicy="on" variableRowHeight="true">
<mx:columns>
<mx:DataGridColumn dataField="dbProduct" headerText="DB Product"/>
<mx:DataGridColumn dataField="entitledQty" headerText="Entitled Quantity"/>
<mx:DataGridColumn dataField="entityId" headerText="Entity Id"/>
<mx:DataGridColumn dataField="entityName" headerText="Entity Name"/>
<mx:DataGridColumn dataField="eventStatus" headerText="Event Status"/>
<mx:DataGridColumn dataField="option" headerText="Description" itemRenderer="renderer.TextInputRenderer"/>
</mx:columns>
</mx:DataGrid>
</mx:VBox>
<mx:Script>
<![CDATA[
import event.ElectionEvent;
private function onOptionSelection(electionEvent : ElectionEvent) : void
{
electionGrid.dispatchEvent(new ElectionEvent(ElectionEvent.OPTION_SELECTED,electionEvent.item));
}
]]>
</mx:Script>
文本输入渲染器:
public class TextInputRenderer extends VBox
override public function set data(value:Object):void
{
_data = value;
_dataGrid = owner as DataGrid;
if(_dataGrid)
_dataGrid.addEventListener(ElectionEvent.OPTION_SELECTED,addTextInput);
}
private function addTextInput(electionEvent : ElectionEvent) : void
{
var option : CAEventOption = electionEvent.item as CAEventOption;
if(option != null)
{
var textInput : TextInput = getChildByName(option.option) as TextInput;
if(textInput == null)
{
textInput = new TextInput;
textInput.name = option.option;
textInput.text = option.option;
textInput.percentWidth = 100;
textInput.percentHeight = 100;
textInput.visible = textInput.includeInLayout = option.selected;
addChild(textInput);
}
else
{
textInput.visible = textInput.includeInLayout = option.selected;
}
}
}
选举事件是一个自定义事件,只要在 OPTION GRID 中选中/取消选中复选框,就会触发并调用监听函数 addTextInput。
private function addTextInput(electionEvent : ElectionEvent) : void
他们是在 TextInput 中保留编辑值的一种方式吗?谁能有解决办法?
【问题讨论】:
标签: apache-flex datagrid itemrenderer textinput