【问题标题】:Deleting Row of Datagrid by clicking a button part of that row in Delete column?通过单击删除列中该行的按钮部分来删除 Datagrid 行?
【发布时间】:2023-03-15 18:54:01
【问题描述】:

当有人单击位于删除列下方的该行的按钮部分时,我想删除我的数据网格的一行。我尝试了许多不同的方法,其中一种是

<mx:DataGrid id="userGrid" dataProvider="{userGridData}" width="800" height="500" itemClick="userGrid_itemClickHandler(event)" creationComplete="userGrid_creationCompleteHandler(event)">
        <mx:columns>
            <mx:DataGridColumn headerText="ID" dataField="user_id" />

            <mx:DataGridColumn headerText="Email" dataField="user_email"/>

            <mx:DataGridColumn headerText="Delete" itemRenderer="ev.renderers.UserGridDelete" id="deleteCol"/>
            <mx:DataGridColumn headerText="Edit" itemRenderer="ev.renderers.UserGridEditRender"/>

        </mx:columns>
    </mx:DataGrid>

项目渲染 ev.renderers.UserGridEditRender 有一个删除按钮列表,用于单击事件它基本上是 userGridData.removeItemAt(userGrid.selectedIndex); (UserGridData = id 为“userGrid”的网格的数据提供者) 但是每当我单击按钮时,就会抛出异常

RangeError: Index '-1' specified is out of bounds.

【问题讨论】:

    标签: apache-flex datagrid row itemrenderer


    【解决方案1】:

    让您的项目渲染器按钮调度一个包含所选“数据”的事件怎么样。

    dispatchEvent( new DataMonkeyEvent(DataMonkeyEvent.DELETE_ROW, this.data) );  //where "this" is the button and the event should bubble.
    

    在外部文档中侦听该事件并相应地编辑您的 userGridData...invalidateList() 如果您没有使用内部扩展数据提供程序来侦听更改 jive 的孩子。

    希望对您有所帮助。 --杰里米

    【讨论】:

    • 我已经尝试过了,有趣的是,只有索引为 0 和 1 的行会抛出异常,其余的效果很好。
    • 你必须显示代码。在您的示例中,您不应引用“deleteCol”。另一个问题是(正如您的代码所说),您没有选定的索引。首先单击网格中的其他位置(电子邮件列),然后使用删除按钮。
    猜你喜欢
    • 2011-04-29
    • 2012-10-19
    • 2015-02-03
    • 2016-04-21
    • 1970-01-01
    • 2021-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多