1

I am trying to have my Flexicious DataGrid ask for confirmation of a change when I click in a cell to edit a value and enter a new value which deviates from the original by a certain percentage. I cannot see an easy way to do this. Initially, I tried to write a itemEditorValidatorFunction, which returns a boolean. This works perfectly for a hard coded return value, but if I try to take the return value from the CloseEvent of an Alert, that value is ignored:

    protected function validateGcCap(editor:UIComponent):Boolean{
        var warningBPDiffVal:Number = Number(5);
        var warningPerCentDiffVal:Number = Number(warningBPDiffVal / 1000);
        var allowChange:Boolean = true;
        var origGcCapVal:Number = Number(managerGrid.getCurrentEditingCell().text);
        var newGcCapVal:Number = Number((editor as TextInput).text);
        var diffVal:Number = Number(newGcCapVal - origGcCapVal);

        if (origGcCapVal > newGcCapVal) {
            diffVal = origGcCapVal - newGcCapVal;
        }

        if (diffVal > warningPerCentDiffVal) {
            //Alert.show("you changed the gccap from " + origGcCapVal + " to " + newGcCapVal + " by " + diffVal);

            function alertCloseHandler(event:CloseEvent):void{
                if (event.detail == Alert.CANCEL) {
                    allowChange = false;
                }
            };

            var alert:Alert = Alert.show("Are you sure that you want to update gcCap% by more than " + warningBPDiffVal + "bps?",
                    "Please Confirm", (Alert.OK | Alert.CANCEL),
                    this, alertCloseHandler);
       }

        return allowChange;
    }

I also tried to write a itemEditor for the grids:FlexDataGridColumn, where I extended com.flexicious.controls.TextInput, but I could not work out which method to override. I wanted to override the method and only make the call to super if the Alert was clicked OK, but I could not see which method I should override. I tried override protected function onTextInput(textEvent:TextEvent):void, but this did nothing.

I would be grateful for any insight into this problem.

2 Answers2

0

Not sure why someone decided to downvote your question, it seems quite valid. From looking at this, the best way for you would be to "undo" the edit when the user selects no on the box. If you have enableTrackChanges on, all you have to do is to remove that change from the dgGrid.changes collection and call dgGrid.refreshCells(). If you dont have enableTrackChanges, all you need to do is to update the dataProvider row with the old value, call dgGrid.refreshCells() and you should be set.

flexicious.com
  • 1,601
  • 1
  • 13
  • 21
  • Thanks. So should I have the same code as above set to be called by itemEditorValidatorFunction="validateGcCap", have the method return true regardless of the user choice of the Alert and have the alertCloseHandler function set the dataProvider row back to what it ready was and then call dgGrid.refreshCells()? Thanks for your help. – Derek Sooman Sep 05 '14 at 07:15
  • The following worked. You must obtain a reference to the Cell before hitting the Alert, then cast the cell.rowInfo.data to a VO and set the value there back to the original value: function alertCloseHandler(event:CloseEvent):void{ if (event.detail == Alert.CANCEL) { IAParamsVO(cell.rowInfo.data).gcCapWrapper = origGcCapVal; managerGrid.refreshCells(); } } – Derek Sooman Sep 05 '14 at 14:07
  • Great to hear, please accept the answer if it resolved your question. – flexicious.com Sep 15 '14 at 12:59
0

This is what works:

    private function validateGcCap(editor:UIComponent):Boolean{
        var warningBPDiffVal:Number = Number(5);
        var cell:IFlexDataGridCell = managerGrid.getCurrentEditingCell();
        var warningPerCentDiffVal:Number = Number(warningBPDiffVal / 1000);
        var origGcCapVal:Number = Number(cell.text);
        var newGcCapVal:Number = Number((editor as TextInput).text);
        var diffVal:Number = Number(newGcCapVal - origGcCapVal);

        if (origGcCapVal > newGcCapVal){
            diffVal = origGcCapVal - newGcCapVal;
        }

        if (diffVal > warningPerCentDiffVal){

            function alertCloseHandler(event:CloseEvent):void{
                if (event.detail == Alert.CANCEL) {
                    IAParamsVO(cell.rowInfo.data).gcCapWrapper = origGcCapVal;
                    managerGrid.refreshCells();
                }
            }

            Alert.show("Are you sure that you want to update gcCap% by more than "
                               + warningBPDiffVal + "bps?", "Please Confirm", (Alert.OK | Alert.CANCEL),
                    this, alertCloseHandler);
        }

        return true;
    }
  • You must obtain a reference to the cell before you make the change, and then in the alertCloseHandler method hitting CANCEL sets the value back to the original. – Derek Sooman Sep 08 '14 at 09:56