问题
I am writing flex code
- first column has checkboxes
- When checkbox is slected then only particular row in datadrid should be enabled, i.e. all other columns I need to enable for particular row
As I am using itemrenderer in each datagridcolumn I can not access its id's outside.
How can I disable or enable rows based on checkbox change?
回答1:
Thanks for the help. I tried using preventDefault, it disables columns but I am not able to enable it back.
To be specific with my requirement I have 3 columns, First contains checkbox and other two contains text boxes,all of these are inside separate itemrenderers of datagrid columns
If checkbox is checked subsequent textboxes in particular row should be editable and when checkbox is unchecked textboxes should not be editable
回答2:
Disabling a row could have different meanings. But if your intention is to disallow the user from being able to edit the row, even when the editable property of the datagrid is set to true, you could use the event:ListEvent and its propertyevent.preventDefault() to achieve this.
On the click of the check-box column, call a function and store the rowIndex through the ListEvent into a global variable checkedIndex. Call the function below on the itemClick property of the datagrid.
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();
}
}
}
More info on ListEvent here.
回答3:
From inside of itemrenderer, you can access the record data by using data.fieldname.
So if you want to change dynamically based on other columns, it doesn't need to access id of component which is inside itemrender.
Just bind the data.
<mx:TextInput enabled="{data.isChecked}"/> <!-- For Flex3 -->
<s:TextInput enabled="{data.isChecked}"/> <!-- For Flex4 -->
Working Example: http://wonderfl.net/c/6MS0
来源:https://stackoverflow.com/questions/36471672/flex-disable-data-grid-row-when-checkbox-is-not-selected