apache-flex - Flex数据网格: Change value based on another value?

标签 apache-flex datagrid

我在 Flex 中有一个 DataGrid,其中一列是复选框,另一列是数值。单击该复选框时,数值应更改,如果未选中该复选框,则数值应更改为 0;如果选中该复选框,则应更改为预定义的最小值。这是我的代码:

<mx:DataGrid x="0" y="45" width="272" height="525" dataProvider="{dp}" variableRowHeight="true" editable="true" id="equipmentDG" verticalAlign="middle">                
    <mx:columns>                    

        <mx:DataGridColumn headerText="" headerStyleName="gridheader" width="20" dataField="included" editorDataField="selected" rendererIsEditor="true">
            <mx:itemRenderer>
                <fx:Component>
                    <mx:CheckBox click="handleClicks(event)">
                        <fx:Script>
                            <![CDATA[
                            public function handleClicks(event:MouseEvent):void
                            {
                                data.included = !data.included;

                                if(data.included && data.antal == 0)     
                                    data.antal = data.minNo; 
                                else if(!data.included) 
                                    data.antal = 0;
                            }
                            ]]>
                        </fx:Script>
                    </mx:CheckBox>
                </fx:Component>
            </mx:itemRenderer>
        </mx:DataGridColumn>
        <mx:DataGridColumn headerText="Antal" headerStyleName="gridheader" width="40" dataField="antal" editorDataField="value" editable="true">
            <mx:itemEditor>
                <fx:Component>

                    <mx:NumericStepper stepSize="1" width="35" height="20"  focusOut="numericstepper1_changeHandler(event)">
                        <fx:Script>
                            <![CDATA[
                            import mx.events.NumericStepperEvent;
                            override public function set data(value:Object):void
                            {
                                super.data = value;

                                if (value && value.hasOwnProperty("minNo"))
                                    minimum = value.minNo;

                                if (value && value.hasOwnProperty("maxNo"))
                                    maximum = value.maxNo;                                              
                            }

                            protected function numericstepper1_changeHandler(event:Event):void
                            {
                                if(data.antal > 0)
                                    data.included = true;
                                else
                                    data.included = false;
                            }

                            ]]>
                        </fx:Script>

                    </mx:NumericStepper>                                        

                </fx:Component>
            </mx:itemEditor>
        </mx:DataGridColumn>


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

数据中的值会更新(当我关闭并打开该对话框时可以看到它),但它不会在数据网格中立即更新。如何在单击复选框后立即使值发生明显变化?

最佳答案

在数据对象中,确保每次包含的属性发生更改时都会触发事件。在第二个 itemRenderer 中监听事件并在属性更改时更新值。

概念上是这样的:

在数据对象中:

private var _included : Boolean;
public function get included():Boolean{
 return this._included;
}

public function set included(value:Boolean):void
 this._included = value;
 this.dispatchEvent(new Event('includedChanged');
}

将渲染器添加到第二列,如下所示:

 <mx:DataGridColumn headerText="Antal" headerStyleName="gridheader" width="40" dataField="antal" editorDataField="value" editable="true">
  <mx:itemRenderer>
   <fx:Component>
   <mx:Label dataChange="onDataChange()" >
    <fx:Script>
     <![CDATA[
      public function onDataChange():void{
       thistext = data['Antal'];
       this.data.addEventListener('includedChanged',onIncludedChange);
      }
      public function onIncludedChange(e:Event):void{
       this.text = data['Antal'];
      }
     ]]>
    </fx:Script>
   </mx:Label>
  </fx:Component>
  </mx:itemRenderer>
  <mx:itemEditor>
   <fx:Component>

    <mx:NumericStepper stepSize="1" width="35" height="20"  focusOut="numericstepper1_changeHandler(event)">
     <fx:Script>
      <![CDATA[
       import mx.events.NumericStepperEvent;
       override public function set data(value:Object):void{
        super.data = value;

        if (value && value.hasOwnProperty("minNo"))
         minimum = value.minNo;

        if (value && value.hasOwnProperty("maxNo"))
          maximum = value.maxNo;                                              
        }

        protected function numericstepper1_changeHandler(event:Event):void
        {
         if(data.antal > 0)
          data.included = true;
         else
          data.included = false;
         }

         ]]>
        </fx:Script>
       </mx:NumericStepper>                                        
      </fx:Component>
     </mx:itemEditor>
    </mx:DataGridColumn>

关于apache-flex - Flex数据网格: Change value based on another value?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3854973/

相关文章:

Java GWT在应用自定义celltable/datagrid css样式时如何编写文件路径

行高度可变的WPF DataGrid

apache-flex - 将 RGB 转换为十六进制

apache-flex - Flex Builder 3 执行旧的源代码

apache-flex - 弹性 3 : dynamically created checkbox column in datagrid - data population issues and event listener

c# - 是否可以设置 DataGrid (SWF) 以调整到最佳大小?

c# - 在 WPF 数据网格中查找行的高度

wpf - 如何更改 WPF DataGridColumn 上的第一个排序方向

apache-flex - Flex - 以更高的 dpi 保存图像

apache-flex - 在 flex builder 中制作一个标签作为 url 链接