简体   繁体   English

禁用Flex DataGrid中的行

[英]Disable rows in Flex DataGrid

Unless I'm missing something obvious here, there is no way of disbabling one or more rows in a DataGrid. 除非我在这里遗漏了一些明显的东西,否则无法在DataGrid中解除一行或多行。 I would expect a disabledRows or disabledRowIndidices property on the DataGrid or List component but that doesn't seem to exist. 我期望DataGrid或List组件上的disabledRows或disabledRowIndidices属性,但似乎不存在。

I found a "rendererArray" property which is scoped to mx_internal and contains all itemrenderers of all cells in the datagrid. 我找到了一个“rendererArray”属性,它的作用域是mx_internal,并包含datagrid中所有单元格的所有itemrenderers。 So I can check the type and the value of the data inside the renderer and enable or disable all cells of the same row, but that feels too much like a hack. 所以我可以检查渲染器内部数据的类型和值,并启用或禁用同一行的所有单元格,但这感觉太像黑客了。

Any suggestions? 有什么建议么?

Edit : I realize that disabling a row could mean different things. 编辑 :我意识到禁用一行可能意味着不同的事情。 In my case it means not being able to edit the row even when the editable property of the datagrid is set to true. 就我而言,即使datagrid的editable属性设置为true,也意味着无法编辑行。 It could however also mean not being able to select a row, but that's not what I'm looking for. 然而,它也可能意味着无法选择一行,但这不是我正在寻找的。

To do this you will need some data for that row to signify that it is uneditable. 为此,您需要该行的一些数据来表示它是不可编辑的。 Then when the "itemEditBeginning" then check the data or row index to enable/disable the default behavior with event.preventDefault ... 然后当“itemEditBeginning”然后检查数据或行索引以启用/禁用event.preventDefault的默认行为...

public function preventEditing(event:DataGridEvent):void
{   
    var status : Boolean = ArrayObjs[rowIndex].isYourCondition;

    if (status == true)
    {
        event.preventDefault();
    }
}

The other option is to make a custom ItemRenderer for your data cell but don't think that is what you want as you would need to make it for each of your cells. 另一个选项是为您的数据单元格创建一个自定义ItemRenderer,但不要认为这是您想要的,因为您需要为每个单元格创建它。

actually this is best done via "itemEditBeginning". 实际上这最好通过“itemEditBeginning”来完成。 Look here for a good tutorial: link text 在这里查看一个很好的教程: 链接文本

Just set a function to the "itemEditBegin"of the DataGrid that does something like this: 只需将函数设置为DataGrid的“itemEditBegin”,它就是这样的:

protected function validateEdition(event:DataGridEvent):void{
    if([EDITION CRITERA NOT MET]){
          event.preventDefault();
    }
}

<mx:DataGrid id="grid" itemEditBegin="validateEdition(event)" editable="true">
      <mx:columns>
         [[YOUR COLUMN CONFIGURATION]]
      </mx:columns>
</mx:DataGrid> 

event.preventDefault() will stop the DataGrid from switching the ItemRenderer to the ItemEditor for so stopping the edition of the row that doesn't meet the criteria. event.preventDefault()将阻止DataGrid将ItemRenderer切换到ItemEditor,以便停止不符合条件的行的版本。 Your DataGrid must be editable for this to Work. 您的DataGrid必须可编辑才能使其工作。

This should do the trick. 这应该可以解决问题。

Alex Harui provides a good example with source here, http://blogs.adobe.com/aharui/2007/06/disabling_list_selection.html It's a bit of a lengthy solution, but covers mouse and keyboard interaction with the datagrid. Alex Harui在这里提供了一个很好的示例源代码, http://blogs.adobe.com/aharui/2007/06/disabling_list_selection.html这是一个冗长的解决方案,但涵盖了与数据网格的鼠标和键盘交互。 I agree with you, it's surprising that there isn't a "built-in" method to do this. 我同意你的观点,令人惊讶的是没有“内置”方法来做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM