【问题标题】:Flex-Disable data grid row when checkbox is not selected未选中复选框时 Flex-Disable 数据网格行
【发布时间】:2016-09-13 18:39:40
【问题描述】:

我正在编写弹性代码

  1. 第一列有复选框
  2. 选中复选框后,应仅启用 datadrid 中的特定行,即我需要为特定行启用的所有其他列

由于我在每个 datagridcolumn 中使用 itemrenderer,我无法在外部访问它的 id。

如何根据复选框更改禁用或启用行?

【问题讨论】:

    标签: apache-flex checkbox


    【解决方案1】:

    感谢您的帮助。 我尝试使用 preventDefault,它会禁用列,但我无法重新启用它。

    为了具体说明我的要求,我有 3 列, 第一个包含复选框,另外两个包含文本框,所有这些都在 datagrid 列的单独 itemrenderers 内

    如果选中复选框,则特定行中的后续文本框应该是可编辑的 并且当复选框未选中时,文本框不应该是可编辑的

    【讨论】:

    • 您能否分享您的代码,以便我们了解您是如何实现这一目标的。
    【解决方案2】:

    禁用一行可能有不同的含义。但是,如果您的意图是禁止用户编辑该行,即使数据网格的可编辑属性设置为 true,您也可以使用 event:ListEvent 及其属性event.preventDefault() 来实现此目的。

    单击复选框列时,调用函数并将rowIndex 通过ListEvent 存储到全局变量checkedIndex 中。在数据网格的 itemClick 属性上调用下面的函数。

    public function disableEditing(event:ListEvent):void
    {   
        if(event.columnIndex == 0)
            //call a function & assign the value into global var checkedIndex
        else
        {
            var currentIndex: Number = event.rowIndex;
            if (currentIndex != checkedIndex)
            {
                event.preventDefault();
            }
        }
    }
    

    更多关于 ListEvent 的信息here

    【讨论】:

      【解决方案3】:

      在 itemrenderer 内部,您可以使用 data.fieldname 访问记录数据。
      所以如果你想根据其他列动态改变,就不需要access id of component which is inside itemrender了。
      只需绑定数据即可。

      <mx:TextInput enabled="{data.isChecked}"/>  <!-- For Flex3 -->
      <s:TextInput enabled="{data.isChecked}"/>   <!-- For Flex4 -->
      

      工作示例:http://wonderfl.net/c/6MS0

      【讨论】:

      • 这个解决方案看起来很棒,但是当我调用刷新时,它也应用了我为复选框列实现的默认排序器,并且选定的行移动到表的顶部,导致我不想要的超级动态排序。我只需要在页面加载时默认对数据进行排序。这就是为什么我想知道我们是否可以有其他选项而不是刷新
      猜你喜欢
      • 2011-03-10
      • 2012-01-21
      • 2010-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-22
      • 2012-12-31
      • 1970-01-01
      相关资源
      最近更新 更多