【问题标题】:Spark DataGrid selected cell edit on keyDownSpark DataGrid在keyDown上选择单元格编辑
【发布时间】:2015-11-19 09:50:45
【问题描述】:

我正在使用火花数据网格。 I want to emulate Excel Behaviour = When single cell is selected and users start to type on keyboard the selected cells goes to editing mode.我通过在第一个 keyDown 事件上启动 gridItemEditorSession 来做到这一点,但我遇到的问题是,在单元格中启动 gridItemEditorSession 值后,第二个 keyDown 删除了第一个 keyDown 字符;/

这里是演示: 只需选择任何单元格并开始输入:

<?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">
    <fx:Script>
        <![CDATA[
            private function onKeyDown():void
            {
                trace(dataGrid.grid.anchorRowIndex)
                trace(dataGrid.grid.caretRowIndex)

                dataGrid.startItemEditorSession(dataGrid.grid.anchorRowIndex, dataGrid.grid.anchorColumnIndex)
            }

            private function onGridRollOver():void
            {

            }
        ]]>
    </fx:Script>

    <s:DataGrid id="dataGrid" requestedRowCount="5" width="350" editable="true"
        height="300" selectionMode="multipleCells" keyDown="onKeyDown()"
        gridRollOver="onGridRollOver()">
        <s:ArrayCollection>
                <s:DataItem key="1000" name="Abrasive" price="100.11" call="false"/>
                <s:DataItem key="1001" name="Brush" price="110.01" call="true"/>
                <s:DataItem key="1002" name="Clamp" price="120.02" call="false"/>
                <s:DataItem key="1003" name="Drill" price="130.03" call="true"/>
                <s:DataItem key="1004" name="Epoxy" price="140.04" call="false"/>
                <s:DataItem key="1005" name="File" price="150.05" call="true"/>
                <s:DataItem key="1006" name="Gouge" price="160.06" call="false"/>
                <s:DataItem key="1007" name="Hook" price="170.07" call="true"/>
                <s:DataItem key="1008" name="Ink" price="180.08" call="false"/>
                <s:DataItem key="1009" name="Jack" price="190.09" call="true"/>             
            </s:ArrayCollection>
        </s:DataGrid>
</s:Application>

【问题讨论】:

  • 我看到我可以按预期编辑单元格中的值。您能否详细说明您的问题?

标签: actionscript-3 apache-flex flex4


【解决方案1】:

我对 Flex 不太熟悉,但听起来您遇到了字符串处理问题。像

private function handleKeydown(e:KeyboardEvent):void
{
    output_txt.text = String.fromCharCode(e.charCode);
}

而不是

private function handleKeydown(e:KeyboardEvent):void
{
    output_txt.appendText(String.fromCharCode(e.charCode));
}

确保将输入附加到文本而不是替换。

【讨论】:

  • 这是内部 DataGrid 实现,所以我无权访问 textField 实例;/所以真正的问题是如何绕过 spark DataGrid 中的这种“内部”行为。
  • 在 api 中找到一种方法,让您可以附加文本,通过在单元格上方创建一个人造文本字段并在键 13 上发送它来一次性发送它,或者重写内部:P
猜你喜欢
  • 2011-10-12
  • 1970-01-01
  • 2012-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-09
  • 2011-07-25
  • 2011-11-27
相关资源
最近更新 更多