2010-09-30 28 views
0

我有一個Flex 4中的數據網格,其中一個NumericStepper作爲數值的編輯器。我可以爲NumericStepper設置預定義的最大值和最小值,但是我需要能夠爲DataGrid中的每一行設置不同的限制。我怎樣才能做到這一點?DataGrid中的NumericStepper的行特定限制

這是DataGrid的代碼:

<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="Benämning" headerStyleName="gridheader" fontSize="12" width="128" dataField="name" editable="false"/> 
     <mx:DataGridColumn headerText="Antal" headerStyleName="gridheader" width="40" dataField="antal" editorDataField="value" editable="true"> 
      <mx:itemEditor> 
       <fx:Component> 
        <mx:NumericStepper minimum="0" maximum="50" stepSize="1" width="35" height="20"></mx:NumericStepper>     
       </fx:Component> 
      </mx:itemEditor> 
     </mx:DataGridColumn> 
    </mx:columns> 
</mx:DataGrid> 

編輯: 基於Flextras答案,我已經改變了NumericStepper行

<mx:NumericStepper minimum="{data.minNo}" maximum="{data.maxNo}" stepSize="1" width="35" height="20"></mx:NumericStepper> 

,但現在我得到的StackOverflowError當我單擊單元格以更改值。我在這裏發佈了一個新問題:StackOverflowError on DataGrid row specific limits in a NumericStepper

回答

2

Te DataGrid只爲屏幕上顯示的內容創建行。它不會爲dataProvider中的每個項目創建行。這被稱爲渲染器回收,並且出於性能原因而完成。

我建議您應該嘗試根據數據對象的元素,而不是基於行的位置,指定NumericStepper的最大值和最小值。基本上,這樣的事情:

<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="Benämning" headerStyleName="gridheader" fontSize="12" width="128" dataField="name" editable="false"/> 
     <mx:DataGridColumn headerText="Antal" headerStyleName="gridheader" width="40" dataField="antal" editorDataField="value" editable="true"> 
      <mx:itemEditor> 
       <fx:Component> 
        <mx:NumericStepper minimum="{data['min']}" maximum="data['max']}" stepSize="1" width="35" height="20"></mx:NumericStepper>     
       </fx:Component> 
      </mx:itemEditor> 
     </mx:DataGridColumn> 
    </mx:columns> 
</mx:DataGrid> 
+0

謝謝。對不起,我不明白,我沒有試圖根據行的位置,但正如你所說,在行數據。我還將data ['min']更改爲data.min,因爲我得到了以下警告:「使用方括號運算符時,數據綁定將無法檢測到更改。對於Array,請使用ArrayCollection.getItemAt()。」但是,現在當單擊以更改步進器中的值時,出現StackOverflow錯誤(!)。有什麼建議麼? – Lizzan 2010-10-01 05:48:56

+0

不是使用綁定,而是監聽itemEditor的dataChange事件,並在其中設置NumericStepper的最小值和最大值。 – JeffryHouser 2010-10-01 12:37:20

+0

謝謝!我接受了我在另一個問題中提出的建議,但總是有很好的選擇! =) – Lizzan 2010-10-04 06:08:23

相關問題