2 Replies Latest reply on Jan 20, 2011 8:43 AM by mstacey01

    Comparing two columns in a datagrid.


      I have a datagrid that has a data provider of some users. The users have a name, address, balance, and payment amount. For the payment amount I'm using a custom MXDataItemRenderer as my TextEditor (not text renderer). What I want to do is validate that the amount they entered in the payment amount is not greater than the balance.


      I've been trying to do this on an itemEditEndHandler, but the problem is that for some reason I don't have the payment amount at that time. I'm wondering what I'm doing wrong or if I'm going about this completely the wrong way.


      Any help would be greatly appreciated.




      Here is my editHandler function

      var item:Object = ((event.currentTarget as DataGrid).dataProvider as ArrayCollection)[event.rowIndex];
      var paymentValidator:PaymentAmountValidator = new PaymentAmountValidator(item.balance);
      paymentValidator.source = this.dataProvider;
      paymentValidator.property = "paymentAmount";



      Here is my custom validator.


      public class PaymentAmountValidator extends Validator
              private var results:Array;
              private var balance:Number;
              public function PaymentAmountValidator(balance:Number = 0){
                  this.balance = balance;
              // Define the doValidation() method.
              override protected function doValidation(value:Object):Array {
                  // Convert value to a Number.
                  var inputValue:Number = Number(value);
                  // Clear results Array.
                  results = [];
                  // Call base class doValidation().
                  results = super.doValidation(value);       
                  // Return if there are errors.
                  if (results.length > 0)
                      return results;
                  // If input value is not a number, or contains no value,
                  // issue a validation error.
                  if (isNaN(inputValue) || !value )
                      results.push(new ValidationResult(true, null, "NaN",
                          "You must enter an amount."));
                      return results;
                  if (inputValue > balance) {
                      results.push(new ValidationResult(true, null, "moreThanBalance",
                          "Payment amount must be less than or equal to balance."));
                      return results;
                  return results;



        • 1. Re: Comparing two columns in a datagrid.
          Flex harUI Adobe Employee

          Get the paymentAmount from the itemEditorInstance.  It hasn't been written

          to the item yet.

          • 2. Re: Comparing two columns in a datagrid.
            mstacey01 Level 1

            Thanks for the answer. I ended up doing it a little differently and instead of catching the itemEditEnd event I added my custom validator to the actual renderer itself, but your advice to use the itemEditorInstance got me the data I needed.


            My validation looked like this before moving it to the custom item editor.


            var item:Object = ((event.currentTarget as DataGrid).dataProvider as ArrayCollection)[event.rowIndex];
            var amountText:String = AmountTextInputRenderer(this.itemEditorInstance).amountText;
            var paymentValidator:PaymentAmountValidator = new PaymentAmountValidator(parseFloat(amountText));
            paymentValidator.source = item;
            paymentValidator.property = "paymentAmount";